Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Detect when application is going to background and foreground. How?

Detect when application is going to background and foreground. How?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 1.4k 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by bogong
    #1

    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.

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      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

      B 1 Reply Last reply
      1
      • JoeCFDJ JoeCFD

        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

        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • JoeCFDJ Offline
          JoeCFDJ Offline
          JoeCFD
          wrote on last edited by
          #4

          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.

          B 1 Reply Last reply
          1
          • JoeCFDJ JoeCFD

            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.

            B Offline
            B Offline
            bogong
            wrote on last edited by bogong
            #5

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

            JoeCFDJ 1 Reply Last reply
            0
            • B bogong

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

              JoeCFDJ Offline
              JoeCFDJ Offline
              JoeCFD
              wrote on last edited by JoeCFD
              #6

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

              1 Reply Last reply
              0
              • Kent-DorfmanK Offline
                Kent-DorfmanK Offline
                Kent-Dorfman
                wrote on last edited by
                #7
                This post is deleted!
                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 Extensions
                • Unsolved