Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Starting external process without quitting it

[Solved] Starting external process without quitting it

Scheduled Pinned Locked Moved General and Desktop
11 Posts 3 Posters 4.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AgentBK
    wrote on last edited by AgentBK
    #1

    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?

    Thanks

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

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      @AgentBK said:

      startDetached

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

      Greetz, Jeroen

      A JeroentjehomeJ 2 Replies Last reply
      0
      • JeroentjehomeJ Jeroentjehome

        @AgentBK said:

        startDetached

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

        A Offline
        A Offline
        AgentBK
        wrote on last edited by
        #3

        @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?

        1 Reply Last reply
        0
        • JeroentjehomeJ Jeroentjehome

          @AgentBK said:

          startDetached

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

          JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          @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");  
          }
          

          Greetz, Jeroen

          FranckynosF 1 Reply Last reply
          0
          • FranckynosF Offline
            FranckynosF Offline
            Franckynos
            wrote on last edited by Franckynos
            #5

            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);
             qApp->quit();
            // COCO still run 
            

            U can pass parameters in function SheelExecuteA if you want.

            PS : I think you need to include windows.h

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AgentBK
              wrote on last edited by
              #6

              @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?

              FranckynosF 1 Reply Last reply
              0
              • JeroentjehomeJ Jeroentjehome

                @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");  
                }
                
                FranckynosF Offline
                FranckynosF Offline
                Franckynos
                wrote on last edited by
                #7

                @Jeroentjehome

                I thry the static function and it works too.

                1 Reply Last reply
                0
                • A AgentBK

                  @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?

                  FranckynosF Offline
                  FranckynosF Offline
                  Franckynos
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    AgentBK
                    wrote on last edited by
                    #9

                    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?

                    1 Reply Last reply
                    0
                    • FranckynosF Offline
                      FranckynosF Offline
                      Franckynos
                      wrote on last edited by
                      #10

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

                      A 1 Reply Last reply
                      0
                      • FranckynosF Franckynos

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

                        A Offline
                        A Offline
                        AgentBK
                        wrote on last edited by
                        #11

                        @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.

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved