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 ?
-
After it exits the exec() routine?
At the statement
@return app.exec();
@
it is meant to stay in memory and execute signals. You need to send a quit signal for closing the application. -
[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.
-
how do i do it in proper way from the QDialogWindow or from the Main ?
how can i send the quit signal? -
sidewinder
im using your solution and its working , i just need to know if its the best way for this -
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] -
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 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.
-
Volker , your code doesn't work for me , only the thing with timer
how can i debug signal/slot to see what is wrong ? -
[quote author="umen242" date="1307707592"]Volker , your code doesn't work for me , only the thing with timer
how can i debug signal/slot to see what is wrong ?[/quote]Then your last window isn't closed. Maybe you just hide() it...