Starting and terminating processes needed by my application
-
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! -
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...)
--
-
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! -
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);@