Process stays in memory after application closes
-
Hello all
i have simple application that start QDialog from its main like this :
@int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(resources);
QApplication app(argc, argv);
QCoreApplication::setApplicationName(APP_NAME);
QCoreApplication::setApplicationVersion(APP_VERISON);
QCoreApplication::setOrganizationDomain(APP_DOMAIN);
app.setStyle("WindowsXP");
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));AuthenticationDialogContainer *pAuthenticationDialogContainer = new AuthenticationDialogContainer();
if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
return 0;
}return app.exec();
}@
when its pass the end of the application that is after app.exec() and the application doing what is suppose to do . when i open the windows xp task manager i see that the process is still in memory and i need manually kill it . how can i prevent it from happening ?
-
[quote author="umen242" date="1307691426"]Hello all
@
if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
return 0;
}@
[/quote]Simplest way to do this is using
@QTimer::singleShot(0, &app, SLOT(quit()));@
instead of
@
return 0;
@ -
@return app.exec(); @ this returns only when you quit your application. Otherwise, it runs in loop and waits for events like redraw, key events, and touch events from user and other components.
-
Your main windows should have a close button at the top right (typically a red button with cross). If you press this button the window will be closed and the application stopped.
Otherwise you may have another button in your dialog window. You have to connect a signal (presumably clicked() ) to the quit slot of your QCoreApplication / QApplication.Assuming that you may create a quit signal in your container:
[quote author="umen242" date="1307691426"]
@int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(resources);
QApplication app(argc, argv);
QCoreApplication::setApplicationName(APP_NAME);
QCoreApplication::setApplicationVersion(APP_VERISON);
QCoreApplication::setOrganizationDomain(APP_DOMAIN);
app.setStyle("WindowsXP");
QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));AuthenticationDialogContainer *pAuthenticationDialogContainer = new uthenticationDialogContainer();
bool boo = connect ( pAuthenticationDialogContainer, SIGNAL ( quit() ), &app, SLOT ( quit () ) );
assert ( boo );
if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
return 0;
}return app.exec();
}@
[/quote] -
[quote author="Volker" date="1307702413"]You can make the application terminate automatically once the last window is closed. Just add this line before your app.exec() call:
@
app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
@[/quote]That is neat! Thanks Volker.