I'm a bit confused about the way we should be using QCoreApplication::exec() for event looping. Here is how I understand the concept in terms of QApplication
int main(int argc,char** argv)
{
wgt.show();
return app.exec();
}
int main(int argc,char** argv)
{
QApplication app(argc, argv);
QWidget wgt;
wgt.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Here, wgt.show() is a non-blocking function and app.exec() is executed right after wgt.show() executes. Which means that everything works fine and we can use click button or other events that are emitted by the widget because app.exec() has already been executed and event looping can be processed.
How does this work in case of QCoreApplication ?
For example
int main(int argc,char** argv)
{
MyClass obj;
QObject::connect(&obj,
SIGNAL(done
()),
&app,
SLOT(quit
()),Qt
::QueuedConnection);
obj.ProcessSomething();
return app.exec();
}
int main(int argc,char** argv)
{
QCoreApplication app(argc, argv);
MyClass obj;
QObject::connect(&obj, SIGNAL(done()), &app, SLOT(quit()),Qt::QueuedConnection);
obj.ProcessSomething();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Here, ProcessSomething() does a lot of things including emitting signals and assigning them to slots. However, those signals are emitted from QProcess and other Qt Objects won't work since app.exec() has not been executed. My question is how to create a non-blocking function in case of console application where we are not waiting for user input. If we move app.exec() above processing, then the application will halt.
The problem here is that there is no GUI that will wait for user action on objects, I've to somehow initiate the event looping before doing the processing and I don't know how ?
Bookmarks