Detect when application is going to background and foreground. How?
-
wrote on 11 Jul 2022, 18:42 last edited by bogong 7 Nov 2022, 18:48
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. -
wrote on 11 Jul 2022, 18:52 last edited by JoeCFD 7 Nov 2022, 18:56
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 -
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#applicationStatewrote on 11 Jul 2022, 18:59 last edited by@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?
-
wrote on 11 Jul 2022, 19:01 last edited by
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. -
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.wrote on 11 Jul 2022, 19:02 last edited by bogong 7 Nov 2022, 19:06@JoeCFD I know. Question is about to know when it's going to move into background but not already in background. Is it for all of platforms on desktop and will it be working on Android? For iOS totally different way.
-
@JoeCFD I know. Question is about to know when it's going to move into background but not already in background. Is it for all of platforms on desktop and will it be working on Android? For iOS totally different way.
wrote on 11 Jul 2022, 19:45 last edited by JoeCFD 7 Nov 2022, 19:46@bogong On linux, it will be hidden when you press alt+tab or a different app is launched on top of it. I do not think there is any scheduled switch and the state transition is quick. Qt app is not thread.
-
wrote on 12 Jul 2022, 01:57 last edited byThis post is deleted!
1/7