PDA

View Full Version : clean exit!!



Raajesh
17th June 2008, 14:18
I have a console based app code is like this,


#include <QApplication>
#include <iostream>
using namespace std;

class dummy : public QObject
{
Q_OBJECT

public:
void callme()
{
cout <<"callme()";
emit taskCompleted();
}
signals:
void taskCompleted();
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication myapp(argc,argv);

dummy me;

QObject::connect (&me,SIGNAL(taskCompleted()),&myapp,SLOT(quit()));
me.callme();
return myapp.exec();
}
It never makes clean exit, it just hangs. once taskCompleted is emitted it should call quit and make clean exit. Is it expected or am I wrong here ?? I have to press ctrl+c to exit.

thanks,
Raajesh

caduel
17th June 2008, 16:33
Your signal is emitted before the event loop is started.
I.e. you start the event loop after the signal was emitted...

If the code works that way, you can just replace

return myapp.exec();
by

return 0;