Open Process from qml



  • Hi everyone,

    I 'm creating some kind of launcher for applications. Therefore I wrote a function to start a process.

    void ApplicationManager::startApplication(const QString& program, const QStringList& arguments) {
      QProcess* myProcess = new QProcess(this);
      myProcess->startDetached(program, arguments);
    }
    

    I created in qml an instance of ApplicationManager and call this function. it works.
    The thing is I want to have control over the process. So if I hit for example Ctrl+Y I want the application to be closed. And the launcher should be displayed again.
    How can I achieve this?



  • @Leon_2001
    Ctrl+Y for close application? Well, up to you. Where do you mean you press the Ctrl+Y: in the subprocess's window (assuming it has one) or the parent process's? Anyway, if you really want the sub-process to be "closed" from the parent process, you'll want to recognise the keys in the parent and then probably https://doc.qt.io/Qt-5/qprocess.html#terminate or more likely in your case https://doc.qt.io/Qt-5/qprocess.html#kill it, not ideal but looks like what you will require.



  • Can't get key input from the other application I suppose as I have not written them.

    Is it maybe possible to kind of embedded the applications in my application? Like to open firefox in a ApplicationWindow. Then I would have full control and could implement a shortcut for returning to the launcher or open a menu where I can do some settings. I know I could do things like this by defining global shortcuts on my linux machine, but then they are global, which is not what I want.


  • Lifetime Qt Champion

    Hi,

    The startDetached overload you use is static so your myProcess creation just uses memory for nothing. If you want to stop that application cleanly, you should get its PID. With all the caveats explained in the documentation to take into account.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.