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. Starting and terminating processes needed by my application
QtWS25 Last Chance

Starting and terminating processes needed by my application

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.6k Views
  • 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.
  • L Offline
    L Offline
    Luc4
    wrote on last edited by
    #1

    Hi! I'm working on an application which needs two other processes to work. The processes must be started and must be terminated when my application starts and quits. These processes may take some time to start, so I would also like to load in a detached thread to prevent my interface from appearing after some seconds:

    @mythread = new QThread();
    QObject::connect(&a, SIGNAL(aboutToQuit()), ProcessHolder::getInstance(), SLOT(mydestroy()));
    QObject::connect(&a, SIGNAL(aboutToQuit()), mythread, SLOT(quit()));
    QObject::connect(mythread, SIGNAL(finished()), mythread, SLOT(deleteLater()));
    ProcessHolder::getInstance()->moveToThread(mythread);
    mythread->start();
    QMetaObject::invokeMethod((FS_ProcessHolder::getInstance()), "init");@

    the mydestroy() method terminates the processes and deleteLater() the object.
    This works correctly when I start my application, wait for the processes to start successfully, then quit my application. The processes are correctly terminated.
    If I start my application and immediately close it, before the processes are completely started, my mydestroy() method is not even invoked. Maybe because the thread owning the object is still busy when mydestroy() is invoked?
    Any idea what I can do to fix this?
    Thanks!

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #2

      What about catching the quit signal in a specific method? This way you could delay main app's quit process long enough for the other processes to finish loading.

      (like, using sigaction, SIGQUIT?, sleep...)

      --

      1 Reply Last reply
      0
      • L Offline
        L Offline
        Luc4
        wrote on last edited by
        #3

        So I should put something like a sleep in the signal handler to give needed time to the other threads to finish the cleanup process?
        Thanks!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          There is no need at all to use threads to start external processes. QProcess will suffice, and is asynchronic by itself already. Simply don't use the synchronous (waitFor...) API, and you have an async setup.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            Luc4
            wrote on last edited by
            #5

            I know that. But I also do other initializations, which are not asynchronous, so that solution seems pretty good. And the initialization doesn't suffer issues of any kind at the moment. My problem is related to the cleanup. Why isn't that method invoked? I need to invoke that method to terminate correctly my processes and cleanup. This way instead, my processes remain running.
            Thanks!

            1 Reply Last reply
            0
            • L Offline
              L Offline
              Luc4
              wrote on last edited by
              #6

              At the end, I came up with a solution which seems to work for the moment. The problem I suppose was related to the fact that the application was terminated before the mydestroy() method ended.
              This executes the method in the same thread and seems to work better:

              @QObject::connect(&a, SIGNAL(aboutToQuit()), ProcessHolder::getInstance(), SLOT(mydestroy()), Qt:DirectConnection);@

              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