Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Force application state change
Qt 6.12 LTS is out! See what's new in the release blog

Force application state change

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DRoscoe
    wrote on last edited by
    #1

    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?

    E 1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      Hi,
      You can create a Timer to change your app state on startup

      D 1 Reply Last reply
      0
      • ODБOïO ODБOï

        Hi,
        You can create a Timer to change your app state on startup

        D Offline
        D Offline
        DRoscoe
        wrote on last edited by
        #3

        @LeLev how?

        1 Reply Last reply
        0
        • D DRoscoe

          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?

          E Offline
          E Offline
          Eeli K
          wrote on last edited by
          #4

          @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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DRoscoe
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved