Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Process stays in memory after application closes
Forum Updated to NodeBB v4.3 + New Features

Process stays in memory after application closes

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 8.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    umen242
    wrote on last edited by
    #1

    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 ?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      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.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sidewinder
        wrote on last edited by
        #3

        [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;
        @

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

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thisisbhaskar
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • U Offline
            U Offline
            umen242
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • U Offline
              U Offline
              umen242
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koahnig
                wrote on last edited by
                #7

                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]

                Vote the answer(s) that helped you to solve your issue(s)

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #8

                  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()));
                  @

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    koahnig
                    wrote on last edited by
                    #9

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

                    Vote the answer(s) that helped you to solve your issue(s)

                    1 Reply Last reply
                    0
                    • U Offline
                      U Offline
                      umen242
                      wrote on last edited by
                      #10

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

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        goetz
                        wrote on last edited by
                        #11

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

                        http://www.catb.org/~esr/faqs/smart-questions.html

                        1 Reply Last reply
                        0

                        • Login

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved