app.exec() never returns?
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!?
Code:
int main(int argc, char *argv[])
{
Q_INIT_RESOURCE(application);
....
int check = app.exec();
cout << "Check: " << check << endl;
return check;
}
Re: app.exec() never returns?
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
Re: app.exec() never returns?
Quote:
Originally Posted by
marcel
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
Re: app.exec() never returns?
Yes, there is a way.
All widgets must be created after the QApplication instance.
Code:
#include <QPushButton>
...
This is where you create the application
...
btn.show();
...
This is the part where you call exec.
This should do it.
Regards