QGuiApplication stops the event loop when the phone is locked when compiling with Qt 5.3 or Qt 5.4 (but not with Qt 5.2)

I created a simple program that reproduces the problem. When I lock my phone, or if I switch to another application on my Android phone, the workflow will continue to print, but the event loop will stop . When I return to my application, the loop cycle resumes.

If I replace QGuiApplication with QCoreApplication, the problem goes away. If I compile Qt 5.2 instead of Qt 5.3, the problem goes away. 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 to prevent QGuiApplication from stopping the event loop when an application loses focus? I need my event handling application, even if it is not in the foreground.

+7
c ++ android qt
source share
1 answer

As already mentioned in my comments, I created a mistake for you at the risk of being rejected, but at least we will receive feedback from official attendants.

QGuiApplication "stops" when you lock your phone or switch application.

Now it’s filmed, which is fair, because, as the applicant claims, you should focus on creating a service, not on activity. However, there is no dedicated Qt API for this yet.

The reason this activity is not a good idea is because the application can be killed even instantly when it gets into the background. In addition, it can drain the battery sooner than the user can expect that, in short, this is seen as an error, not a function in 5.2 on the part (s), which seems to be fixed.

Here you can find some help on how to create a service for today:

Create a background service with Qt on android

+3
source share

All Articles