Detect when application is going to background and foreground. How?
-
Hello all!
Got stacked on simple issue - detect when application is going to background and foreground. Is there any working examples. Remember only that it's somehow related to QGuiApplication.
Could someone refresh my memory?
There are ApplicationState:
enum ApplicationState { ApplicationSuspended = 0x00000000, ApplicationHidden = 0x00000001, ApplicationInactive = 0x00000002, ApplicationActive = 0x00000004 };
And it's working in QML:
Connections { target: Qt.application; function onStateChanged(inState) { console.log(Qt.application.state) } }
But there are nothing about background exactly.
Perfectly aware of how to develop background handler for iOS (https://youtu.be/g0W6yZXj3Yw) but nothing about other platforms in my memory. Totally forgotten. -
Qt::ApplicationHidden == The application is hidden and runs in the background.
Qt::ApplicationState QGuiApplication::applicationState() <==== static func. You can check it at any time and anywhere.
https://doc.qt.io/qt-5/qguiapplication.html#applicationState -
@JoeCFD Thx for rapid reply.
Is there in Qt kind of lifecycle like in iOS: didBecomeActive, willBecomeBackground, didBecomeBackground and etc? Or it just only background (hidden) and only foreground (active)? Is there any description of other states with examples?
-
https://doc.qt.io/qt-5/qt.html#ApplicationState-enum
there are only 4. But when the state changes, you link the signal onStateChanged(inState) to a slot. You will know its state. -
This post is deleted!