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. Finishing (not killing) a QProcess

Finishing (not killing) a QProcess

Scheduled Pinned Locked Moved General and Desktop
16 Posts 3 Posters 16.2k 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.
  • raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #4

    whats the behavior when calling QProcess::terminate()?

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    1 Reply Last reply
    0
    • N Offline
      N Offline
      ningu
      wrote on last edited by
      #5

      The process quits just like with QProcess::close()

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vezprog
        wrote on last edited by
        #6

        You might want to look at QSharedMemory or QUdpSocket to command the process to cleanly shutdown, then call waitForFinished() on the QProcess (if you have the ability to edit the source of the child process to implement the shared memory or socket watch).

        You also can use IPC messaging built right into QProcess to send messages to the application using std out.

        1 Reply Last reply
        0
        • N Offline
          N Offline
          ningu
          wrote on last edited by
          #7

          I can edit the source of the child process because I coded it, but if there's an easier way, I'd rather do that.

          Sending an exit command to the child process seems to be the way. Apparently
          @myProcess->terminate()@

          does just that, but it ain't working. So I checked the documentation and found that maybe I could use something similar to this code
          @QProcess process1;
          QProcess process2;

          process1.setStandardOutputProcess(&process2);

          process1.start("command1");
          process2.start("command2");@

          Although I get the idea, I don't know how to implement it in my case... Since I have just one child process, should I pipe the command from the Qt app to the child process? Can't I just send a command to the child process?

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #8

            so how does your child-process react on the close event? Did you implement any special behavior so the app quits immediately?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • N Offline
              N Offline
              ningu
              wrote on last edited by
              #9

              bq. how does your child-process react on the close event?

              I don't quite understand what you mean by that. It just closes, like when killing it.

              1 Reply Last reply
              0
              • raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by
                #10

                i meant did you reimplement the close event handler in your child-process application, so the event loop doesn't exits "cleanly"?

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                0
                • N Offline
                  N Offline
                  ningu
                  wrote on last edited by
                  #11

                  On (properly) closing, the child process sends an OSC message (implemented in the destructor of the child process).

                  If I hit CMD-Q (or ESC) when the child-process window is focused, the message is sent, but if I close it with
                  @myProcess->terminate() // or myProcess->close()@

                  the message is not sent. Therefore, I assume that the process is abruptly killed. Is that what you where asking?

                  1 Reply Last reply
                  0
                  • raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by
                    #12

                    ok got you now.... somehow i thought you are working on a Windows system. On windows you receive a CLOSE event. On Unix-like system you receive SIGTERM signal which closes the application when they are not handled.

                    So you will have to catch the SIGTERM signal and call qApp->closeAllWindows() for example.

                    Todo so you can follow this "example":http://qt-project.org/doc/qt-5.0/qtdoc/unix-signals.html (code should be the same for Qt4).

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • N Offline
                      N Offline
                      ningu
                      wrote on last edited by
                      #13

                      I should've said that I was on a mac, sorry.

                      I see what you mean. But this is platform-dependent, right? I'd have to catch the platform on which the app is running and then handle it appropriately.

                      Anyhow, I think we're gonna go another way. We'll code the child process to terminate on receiving a "terminate" OSC message, that will be sent by the Qt app.

                      I don't know if it's of your interest or it might help to understand the problem better, but maybe a short explanation of our project would be useful: we have a server app (the child process) and a client GUI (the Qt app I'm working on) that communicate via OSC messages. The idea is to be able to develop other clients with other languages in the future, hence the OSC. The GUI must be able to boot and halt the server and do some stuff after it has started or stopped.

                      Thanks a lot for you help, anyway. It threw some light on the problem and helped me understand many things.

                      Cheers!

                      1 Reply Last reply
                      0
                      • raven-worxR Offline
                        raven-worxR Offline
                        raven-worx
                        Moderators
                        wrote on last edited by
                        #14

                        [quote author="ningu" date="1379498280"]I should've said that I was on a mac, sorry.[/quote]
                        i could have asked so nvm.

                        [quote author="ningu" date="1379498280"]
                        I see what you mean. But this is platform-dependent, right? I'd have to catch the platform on which the app is running and then handle it appropriately.[/quote]
                        yes it is. But you can easily handle this by using the "platform macro":http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#Q_OS_UNIX.

                        If you follow my example it could be as simple as that:
                        @
                        int main ()
                        {
                        #if defined(Q_OS_UNIX)
                        MyDaemon myDaemon;
                        #endif
                        QApplication app;
                        ...
                        return app->exec();
                        }
                        @

                        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                        If you have a question please use the forum so others can benefit from the solution in the future

                        1 Reply Last reply
                        0
                        • N Offline
                          N Offline
                          ningu
                          wrote on last edited by
                          #15

                          Interesting. I may consider using it.

                          Thanks again. You've been very helpful!

                          1 Reply Last reply
                          0
                          • raven-worxR Offline
                            raven-worxR Offline
                            raven-worx
                            Moderators
                            wrote on last edited by
                            #16

                            i've updated my post how you could use the macro with the example.

                            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                            If you have a question please use the forum so others can benefit from the solution in the future

                            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