[Solved]Login dialog and problem with quit app
I have a problem with closing properly an application. 8 months ago I found a web with solution, but now that url is broken and I need yours help. I remember that problem is in application event loop, because when dialog is analised and closed then an event loop is not running yet. Here is my code – what should I add to resolve this issue?
- int main(int argc, char *argv[])
- {
- LogInDialog logInDialog; // QDialog class
- logInDialog.exec();
- int dialogResult = logInDialog.result();
- {
- MainWindow w;
- w.show();
- }
- // if a dialogResult is not equal QDialog::Accepted then I want to close app, but now an application is running
- return a.exec();
- }
5 replies
Also you can write like this:
- LogInDialog logInDialog; // QDialog class
- return -1;
- MainWindow w;
- w.show();
- return a.exec();
So as I understand you have two buttons in your dialog (Ok & Cancel),
if you want that dialog return you QDialog::Accepted or QDialog::Rejected
you need to connect your buttons to dialog’s slots accept [doc.qt.nokia.com] and reject [doc.qt.nokia.com]
Example:
- {
- public:
- TestDialog()
- {
- connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
- connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
- layout->addWidget(buttonBox);
- setLayout(layout);
- }
- };
and main
- int main(int argc, char *argv[])
- {
- TestDialog dlg;
- return -1;
- Widget w;
- w.show();
- return a.exec();
- }
All works fine.
You must log in to post a reply. Not a member yet? Register here!

