Solved Force application state change
-
I have a QML based app which runs on Windows, Linux and iOS.
On iOS, I get an application state change when the app starts. On Windows, I only get a state change on startup if I change from full screen to windowed. I assume this is because the app defaults to full screen? I need a way to always get an application state change on startup.
Any idea how to do this? Should I start it minimized so any focus change causes a state change?
-
Hi,
You can create a Timer to change your app state on startup -
@LeLev how?
-
@DRoscoe Why do you need that, and what "application state" you mean? What do you want to achieve in the end? Such state seems to be platform dependent if you don't get it on all platforms. Maybe there exists an altogether different way to achieve your purpose. One way could be to add a timer somewhere as @LeLev mentioned. Just try adding a zero-time Timer in the e.g. ApplicationWindow and starting it in Component.onCompleted. It's put in the event queue but onTriggered is executed only when everything else which were in the queue when the timer was started has been executed.
-
I did manage to figure out how to force an application state change at start-up, but that did not solve my problem. For anyone interested in how I forced the application state change, I added the following code in my main function:
qRegisterMetaType<Qt::ApplicationState>("Qt::ApplicationState"); QMetaObject::invokeMethod(mainClass, "handleApplicationStateChange", Qt::QueuedConnection, Q_ARG(Qt::ApplicationState, Qt::ApplicationActive));
In the end I ended up solving my problem by making the ApplicationStateChange a no-op for Windows/Linux and using a different signal (which I can reliably control) to initiate the app in general.