Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] process stays in memory after application closes

    General and Desktop
    4
    7
    1451
    Loading More Posts
    • 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.
    • P
      poketmonister last edited by

      @selectiondialog.cpp

      #include <QtWidgets>
      #include "selectiondialog.h"

      selectionDialog::selectionDialog(QWidget *parent):QDialog(parent)
      {
      setupUi(this);
      connect(okButton,SIGNAL(clicked()),this,SLOT(accept()));
      connect(cancelButton,SIGNAL(clicked()),this,SLOT(reject()));
      }
      void selectionDialog::setupSelectionTable()
      { }
      void selectionDialog::adjustSize()
      { }
      void selectionDialog::results()
      { }

      main.cpp
      #include <QApplication>
      #include "selectiondialog.h"

      int main(int argc,char* argv[])
      {
      QApplication app(argc,argv);

      selectionDialog *dialog = new selectionDialog;
      dialog->show();
         if(dialog->exec&#40;&#41;&#41;
             dialog->results();
      app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
      return app.exec&#40;&#41;;
      

      }@

      not working please help i have to manually close the process from task manager.

      I noticed one thing wierd...
      if i remove

      @if(dialog->exec())
      app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));@

      it works.. plz tell me y and help me. i'm new

      1 Reply Last reply Reply Quote 0
      • E
        Eddy last edited by

        Hi pocketmonster,

        welcome to the DevNet forumls.

        Could you please start new topics instead of continuing in old ones?

        I will separate them now.

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply Reply Quote 0
        • M
          maximus last edited by

          Hi,

          Could you try removing the "if" before dialog->exec()
          you want to do something like this to get the result from the dialog

          @int result = dialog->exec()
          if (result == 0)
          qDebug() << "result 0"
          else
          qDebug() << "result 1"@


          Free Indoor Cycling Software - https://maximumtrainer.com

          1 Reply Last reply Reply Quote 0
          • P
            poketmonister last edited by

            maximus i tried your code and it displayed results in console correctly but refused to close.
            i had to use "ctrl + c" in the command prompt to close it.
            plz help any help will be appreciated

            once again when i removed dialog->exec(), it closed fully.

            why cant i use dialog->exec() ??
            is there any other way to get exit status of dialog

            1 Reply Last reply Reply Quote 0
            • A
              andreyc last edited by

              If all your app is one dialog then you can use dialog->exec() instead of app->exec()
              Something like this
              @
              int main(int argc,char* argv[])
              {
              QApplication app(argc,argv);

              selectionDialog *dialog = new selectionDialog;
              dialog->show();
              if(dialog->exec&#40;&#41;) {
                  dialog->results();
              }
              return 0;
              

              }
              @

              1 Reply Last reply Reply Quote 0
              • P
                poketmonister last edited by

                It finally worked....thanks andreyc.

                but could u explain when and why both can\cant be used together.
                i'm having a lot of confusions.

                1 Reply Last reply Reply Quote 0
                • A
                  andreyc last edited by

                  I would suggest you to read some "books about Qt development":https://qt-project.org/books
                  Some of them are for Qt4 but there is no big difference in the core of Qt between 4 and 5.

                  Here is how I understand it:
                  Both exec()s from QApplication and QDialog call the same QEventLoop::exec() to procees the events, like user input. So you don't need to call both if you have only one dialog.

                  If you create main window (QMainWindow or QWidget) then you will need to run app.exec() to process the events from the main window.

                  If you need to do some operation on top of the main window like open a file or select a color then you will call QDialog::exec() to process events for the dialog.

                  With the main window QApplication will receive a close signal when main window is closed.

                  PS: Please add '[SOLVED]" at the title of you original post.

                  1 Reply Last reply Reply Quote 0
                  • First post
                    Last post