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. [SOLVED] process stays in memory after application closes
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] process stays in memory after application closes

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 1.9k 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.
  • P Offline
    P Offline
    poketmonister
    wrote on last edited by
    #1

    @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
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      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
      0
      • M Offline
        M Offline
        maximus
        wrote on last edited by
        #3

        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
        0
        • P Offline
          P Offline
          poketmonister
          wrote on last edited by
          #4

          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
          0
          • A Offline
            A Offline
            andreyc
            wrote on last edited by
            #5

            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
            0
            • P Offline
              P Offline
              poketmonister
              wrote on last edited by
              #6

              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
              0
              • A Offline
                A Offline
                andreyc
                wrote on last edited by
                #7

                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
                0

                • Login

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