• May 19, 2024, 05:56:38 pm

Author Topic: Kill a process from Qt/QML  (Read 1500 times)

0 Members and 1 Guest are viewing this topic.

Offline huellif

  • Developer
  • Christmas Santa
  • ****
  • Posts: 402
  • Reputation: 212
Kill a process from Qt/QML
« on: August 19, 2013, 02:47:21 am »
Hi,
I tried to kill processes via Qt/QML and no Qt API works (e.g. QProcess:terminate("test.exe");

The native C++ way works fine, check this tutorial:

1. add
Code: [Select]
TARGET.CAPABILITY += PowerMgmt
LIBS += apgrfx.lib
to your .pro file into symbian part

2. include
Code: [Select]
#include <apgtask.h>
#include <eikenv.h>
to your class

3. create a void method:
Code: [Select]
yourClass:void kill(QString process) or Q_INVOKABLE void kill(QString process)
    {
       TPtrC16 symprocess(reinterpret_cast<const TUint16*>(process.utf16())); //convert QString to native Char
       TFullName res;
       TFindProcess find(symprocess);
       while(find.Next(res) == KErrNone)
       {
           RProcess ph;
           User::LeaveIfError(ph.Open(find));
           ph.Kill(KErrNone);
           ph.Close();
       }


4.
if you want to kill by UID:
write your UID into "*[]*" without 0x, e.g. "*[100058F3]*"

if you want to kill by name:
use add a * to .exe name, e.g. "sysap.exe*"

two examples:
TFindProcess find(_L("*[100058F3]*")); //reboot via UID
TFindProcess find(_L("sysap.exe*")); //reboot via Name

Regards

P.S.: Killing sysap.exe a.k.a. 0x100058F3 causes a reboot, offical reboot API is private, so this is a nice workaround
« Last Edit: October 29, 2013, 06:29:15 pm by huellif »

Offline mahindar

  • Developer
  • New Member
  • ****
  • Posts: 25
  • Reputation: 11
  • Symbian Power User
Re: Kill a process from Qt/QML
« Reply #1 on: August 19, 2013, 01:20:37 pm »
Nice tutorial mate :)

Offline huellif

  • Developer
  • Christmas Santa
  • ****
  • Posts: 402
  • Reputation: 212
Re: Kill a process from Qt/QML
« Reply #2 on: August 19, 2013, 04:25:52 pm »
currently I am working on a helper class for QtQuick.
Done:
- copy file
- delete files
- launch apps
- kill apps
- reboot the phone

will try to implement more stuff, e.g. check if there a file, copy and overwrite instead of usual copy, maybe a cenrep call

everything works fine from QtQuick, it's part of DelightApp.

edit:
added restart the app
« Last Edit: August 20, 2013, 02:50:31 am by huellif »