PDA

View Full Version : application never quits



harmodrew
5th August 2010, 19:21
hello! I'm writing the following application:

main.cpp:



#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QInputDialog>

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

MainWindow w;

QInputDialog id;
bool ans1, ans2;
int i1 = id.getInt(&w, w.tr("Title"), w.tr("Text"),0,0,20,1,&ans1));
int i2 = id.getInt(&w, w.tr("Title"), w.tr("Text"),0,0,20,1,&ans2));

if (ans1 && ans2)
{
w.showMaximized();
}
else
{
w.close();
}

return a.exec();

}


If I chose "OK" for both the first input dialog and the second one then the program continues rightly and clicking the classic "X" it exits correctly.
While if I chose "Cancel" in one of the input dialogs the window doesn't show (and I want it) but the application doesn't quit at all. It remains running in RAM.
I found this behaviour by debugging the program putting a breakpoint at the row "return a.exec();". This instruction never stop (so the program loops in the exec() function). what can it be?

thanks

Lykurg
5th August 2010, 19:43
it runs because it is not stopped by e.g. closing the last window. but you can simply avoid it by writing
return 0; in your else brace.

harmodrew
6th August 2010, 00:56
thanks, it worked :)