[SOLVED] process stays in memory after application closes



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


  • Moderators

    Hi pocketmonster,

    welcome to the DevNet forumls.

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

    I will separate them now.



  • 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"@



  • 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



  • 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;
    

    }
    @



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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.