June 10, 2011

umen242 umen242
Ant Farmer
326 posts

process stays in memory after application closes

 

Hello all
i have simple application that start QDialog from its main like this :

  1. int main(int argc, char *argv[])
  2.  {
  3.      Q_INIT_RESOURCE(resources);
  4.      QApplication app(argc, argv);
  5.   QCoreApplication::setApplicationName(APP_NAME);
  6.   QCoreApplication::setApplicationVersion(APP_VERISON);
  7.   QCoreApplication::setOrganizationDomain(APP_DOMAIN);
  8.   app.setStyle("WindowsXP");    
  9.   QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
  10.   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  11.    
  12.          AuthenticationDialogContainer *pAuthenticationDialogContainer = new AuthenticationDialogContainer();
  13.    if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
  14.    return 0;
  15.   }
  16.  
  17.  
  18.  
  19.      return app.exec();
  20. }

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 ?

10 replies

June 10, 2011

koahnig koahnig
Mad Scientist
2103 posts

After it exits the exec() routine?
At the statement

  1. return app.exec();

it is meant to stay in memory and execute signals. You need to send a quit signal for closing the application.

June 10, 2011

sidewinder sidewinder
Ant Farmer
65 posts
umen242 wrote:
Hello all
  1.    if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
  2.    return 0;
  3. }

Simplest way to do this is using

  1. QTimer::singleShot(0, &app, SLOT(quit()));
instead of
  1. return 0;

 Signature 

“Never memorize what you can look up in books.”
Albert Einstein

June 10, 2011

Vijay Bhaska Reddy Vijay Bhaska Reddy
Lab Rat
399 posts

  1. 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.

June 10, 2011

umen242 umen242
Ant Farmer
326 posts

how do i do it in proper way from the QDialogWindow or from the Main ?
how can i send the quit signal?

June 10, 2011

umen242 umen242
Ant Farmer
326 posts

sidewinder
im using your solution and its working , i just need to know if its the best way for this

June 10, 2011

koahnig koahnig
Mad Scientist
2103 posts

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:

umen242 wrote:

  1. int main(int argc, char *argv[])
  2.  {
  3.      Q_INIT_RESOURCE(resources);
  4.      QApplication app(argc, argv);
  5.   QCoreApplication::setApplicationName(APP_NAME);
  6.   QCoreApplication::setApplicationVersion(APP_VERISON);
  7.   QCoreApplication::setOrganizationDomain(APP_DOMAIN);
  8.   app.setStyle("WindowsXP");    
  9.   QTextCodec::setCodecForTr(QTextCodec::codecForName("utf8"));
  10.   QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8"));
  11.    
  12.   AuthenticationDialogContainer *pAuthenticationDialogContainer = new uthenticationDialogContainer();
  13.   bool boo = connect ( pAuthenticationDialogContainer, SIGNAL ( quit() ), &app, SLOT ( quit () ) );
  14.   assert ( boo );
  15.    if(pAuthenticationDialogContainer->exec() != QDialog::Accepted ) {
  16.    return 0;
  17.   }
  18.  
  19.  
  20.  
  21.      return app.exec();
  22. }

June 10, 2011

Volker Volker
Robot Herder
5428 posts

You can make the application terminate automatically once the last window is closed. Just add this line before your app.exec() call:

  1. app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));

June 10, 2011

koahnig koahnig
Mad Scientist
2103 posts

Volker wrote:
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), &app, SLOT));
@

That is neat! Thanks Volker.

June 10, 2011

umen242 umen242
Ant Farmer
326 posts

Volker , your code doesn’t work for me , only the thing with timer
how can i debug signal/slot to see what is wrong ?

June 10, 2011

Volker Volker
Robot Herder
5428 posts
umen242 wrote:
Volker , your code doesn’t work for me , only the thing with timer how can i debug signal/slot to see what is wrong ?

Then your last window isn’t closed. Maybe you just hide() it…

 
  ‹‹ is it feasable to copy a Qt class into my project and build it in there      PNG compression method 0 ››

You must log in to post a reply. Not a member yet? Register here!