PDA

View Full Version : app.exec() never returns?



stealth86
17th July 2007, 19:03
Whenever I run my program, the call to app.exec() from the Main function never returns. My program hangs and I end up killing it. This is true if it's run from a debugger or stand alone.

I'm using Qt 4.2 on Kubuntu 7.04 Linux.

I tried checking the return code from app.exec(), but since it never returns I never see it. The code executes successfully up to int check = app.exec(), at which point it hangs, though the code doesn't crash.

Any thoughts?

EDIT:: I've also tried commenting out all of the code between the declaration of app and the call to app.exec(). It still hangs!?


int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(application);
QApplication app(argc, argv);

....


int check = app.exec();
cout << "Check: " << check << endl;
return check;
}

marcel
17th July 2007, 19:12
Do you create any widget?I mean, a widget that is displayed.
Because exec() is actually a loop that exits when you call quit or exit.
When you press the close("x") button in a window, then exit(0) is called. Therefore the event loop exits.

So, most likely you did not create a main widget.

If you did, then check your code in other parts of the application. Maybe an infinite loop :)?

Regards

stealth86
17th July 2007, 19:37
Do you create any widget?I mean, a widget that is displayed.
Because exec() is actually a loop that exits when you call quit or exit.
When you press the close("x") button in a window, then exit(0) is called. Therefore the event loop exits.

So, most likely you did not create a main widget.

If you did, then check your code in other parts of the application. Maybe an infinite loop :)?

Regards

I think that's it, I'm not yet creating any windows for display. Is there any way to get around this until I'm ready to put up a window? ( Or maybe I'll just dummy it up with a blank widget. )

Oh, and thanks for the explanation of the exec function.
I'm pretty new to Qt as you can probably guess, so that was good. :P

marcel
17th July 2007, 19:41
Yes, there is a way.
All widgets must be created after the QApplication instance.


#include <QPushButton>

...
This is where you create the application
...
QPushButton btn("Temporary button", NULL);
btn.show();
...
This is the part where you call exec.
This should do it.
Regards