[SOLVED] process stays in memory after application closes
-
wrote on 3 Apr 2014, 12:32 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()) dialog->results(); app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit())); return app.exec();
}@
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
-
wrote on 3 Apr 2014, 13:13 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.
-
wrote on 3 Apr 2014, 13:18 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"@ -
wrote on 3 Apr 2014, 13:49 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 appreciatedonce 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 -
wrote on 3 Apr 2014, 16:50 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()) { dialog->results(); } return 0;
}
@ -
wrote on 3 Apr 2014, 17:21 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. -
wrote on 4 Apr 2014, 03:51 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/7