I have created a simple program that reproduces the problem. When I lock the phone, or if I switch to another application in my android phone, the worker thread continues printing, but the event loop stops. When I switch back to my application, the event-loop resumes.
If I replace QGuiApplication with QCoreApplication, the problem disappears. If I compile with Qt 5.2 instead of Qt 5.3, the problem disappears. Qt 5.4 has the same problem as Qt 5.3.
static int count = 0;
void workerThread()
{
while (1) {
qDebug("Worker thread %d", count++);
sleep(1);
}
}
void MyObject::step()
{
qDebug("Event loop %d", count++);
}
int main(int argc, char *argv[])
{
QGuiApplication a(argc, argv);
MyObject w;
QTimer timer;
QObject::connect(&timer, SIGNAL(timeout()), &w, SLOT(step()));
timer.start(1000);
QtConcurrent::run(workerThread);
return a.exec();
}
How do I prevent QGuiApplication from stopping the event loop when the app loses focus? I need my app to process events even when not in the foreground.