View Full Version : how to stop QProcess in app.

5th October 2010, 11:34

#include <QtGui/QApplication>
#include <QProcess>

int main(int argc, char *argv[])
QApplication a(argc, argv);
QProcess *myProcess = new QProcess;
//QObject::connect(myProcess,SIGNAL(destroyed()),myP rocess,SLOT());
return a.exec();

here when the process->start is used the Notepad application is opening but when I close the notepad the app should also close, in QTCreator it still showing as running in the application output.
how to close the QApplication when the QProcess or the application opened using the qprocess is closed.
here I tried to use the signal and slot but how to close the main app ?

5th October 2010, 11:40
Please note the difference between [QTCLASS] and [CODE]!

You have to connect to the quit slot of the application object.

5th October 2010, 18:08
You can just remove a.exec();

5th October 2010, 20:33
If he removes a.exec() then both his application and the child process will exit immediately.

6th October 2010, 05:50
if I remove the return a.exec() the application is opened but if I want to interact with any event then its a problem. so I want to close the application only when I require to close it so that's the reason why I am trying to use the connect statement. I want to interact and find if the notepad is closed if its closed then only the main app should be closed.

how to connect the quit slot of the application to the qt class ?

like if I had 2 processes and if one of it is close then the other one should also close.

6th October 2010, 07:10
Then you have to create a custom slot where you also close the second app. On how to do that, read about signals and slots in the documentation.