Important: Please read the Qt Code of Conduct -

[Solved] Starting external process without quitting it

  • Hi

    I would like to know how to start an external application (.exe) from qt application without stopping it when the qt application quits.
    QProcess seems to be the answer, but no matter which method I use, the external process will be closed as soon as the qt application is closed. I tried start(), startDetached(), execute(), etc., but it will always be closed in the end. I also tried to use setParent(NULL), but this doesn't work either. Any ideas?


    SOLUTION: It is NOT related to the Qt version but rather to the build mode. When running in release mode, the problem is gone.

  • @AgentBK said:


    That should work. It does for me anyway ;-)
    Do you connect stop signal of the QProcess etc?

  • @Jeroentjehome I don't connect the stop signal. Can you explain what you mean? Connect to what? My problem is that as soon as the main application closes, all the processes called by the QProcess also close.
    I am running in the debug mode. Shouldn't matter, right?

  • @Jeroentjehome
    BTW do you use the static implementation of QProcess??
    Or do you create an object that is owned by your parent class? Then Qt will delete it when your program stops and thus kills the QProcess!!
    So use:

    // Start Program:
    bool Succes_b = QProcess::startDetached(MyExternalProgram.exe);
    if (Succes_b == false)
        QMessageBox::warning(this, "Failed", "Failed to start program");  

  • Hi

    @AgentBK , I need to use this too.

    In Qt 4.x it works with QProcess.startDetach() but with Qt 5.x I have some trouble.

    So I found and other methode to do this, an it work perfeclty :

    Too launch COCO_installer.exe

    QString path = "path/COCO_installer.exe"
    ShellExecuteA(NULL, (LPCSTR)"open", (LPCSTR)path.toLatin1(), NULL, NULL, SW_SHOWNORMAL);
    // COCO still run 

    U can pass parameters in function SheelExecuteA if you want.

    PS : I think you need to include windows.h

  • @Jeroentjehome I tried also static and the same problem happens. Which Qt version are you using?

    @Franckynos I tried your code. It doesn't run the executable for me. I am also using Qt 5.x. Could it actually be version related?

  • @Jeroentjehome

    I thry the static function and it works too.

  • @AgentBK
    I use Qt 5.4.1 and both solution work for me...
    Oh !! and other thing.
    I remember why I use ShellExecuteA instead of startdetached because I have some troubles with UAC of windows sometime UAC block the execution.

  • Hmmm I tried to run the static approach in release mode now and it seems to not close the process, while in debug it does. Interesting. Anyone cares to confirm this?

  • pay attention with startdetached, you can have some troubles with UAC under windows.

  • @Franckynos I see what you mean. Good to know. However, this is not a problem in this case because the application will be shipped with the hardware, so I can take care of it in advance.

    Thanks all for helping with the problem. Anyway, if anyone could confirm that the process gets closed in the debug mode that would be great, so at least I know the problem is not on my side.

Log in to reply