Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Qt Android application. Backround swipe closure handling

Qt Android application. Backround swipe closure handling

Scheduled Pinned Locked Moved Solved Mobile and Embedded
7 Posts 2 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.
  • D Offline
    D Offline
    deleted510
    wrote on last edited by
    #1

    Hi guys,

    I need help with clean exit when user shuts down application from background (swipe quit/kill).

    0_1561456292959_ScreenOnActivity.png

    I want to call method from class that is written in C++, in onDestroy() method.
    Problem is that one is .java and other .cpp

    Is there a way, and how, to handle that swipe from .cpp file or it must be done in .java?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deleted510
      wrote on last edited by
      #2

      For Linux, Windows and MACOSX (desktop app) i have done this way and it is working without problems0_1561457002003_closeEvent.png

      I tried to add Android but its not working. I tried also to call closeEvent in destructor ~MainWindow() but still no effect.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        deleted510
        wrote on last edited by
        #3

        I have found what is the problem, but still cannot find the solution.

        When i press BACK BUTTON, this is the order of events:
        1. closeEvent() ---> most important thing for my app, cleanup done there
        2. onPause
        3. onStop
        4. onDestroy

        But when i press HOME BUTTON, this is the order of events:
        2. onPause
        3. onStop
        4. onDestroy

        I tried adding finish(), but even that is not working(closeEvent() is ALWAYS missing )

        Can anyone tell me am i doing something wrong or how can mimic BACK BUTTON by pressing HOME BUTTON?

        J.HilkJ 1 Reply Last reply
        0
        • D deleted510

          I have found what is the problem, but still cannot find the solution.

          When i press BACK BUTTON, this is the order of events:
          1. closeEvent() ---> most important thing for my app, cleanup done there
          2. onPause
          3. onStop
          4. onDestroy

          But when i press HOME BUTTON, this is the order of events:
          2. onPause
          3. onStop
          4. onDestroy

          I tried adding finish(), but even that is not working(closeEvent() is ALWAYS missing )

          Can anyone tell me am i doing something wrong or how can mimic BACK BUTTON by pressing HOME BUTTON?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @Stasa-Sekulic
          well, on mobile, when your app gets pushed into the back ground, the application state is changed to suspended

          https://doc.qt.io/qt-5/qguiapplication.html#applicationStateChanged

          you could listen for that signal and react accordingly ?


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

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

            @J-Hilk

            Thanks for the hint!

            Problem is that my class is derived from QWidget.
            0_1561640944704_8fde3df4-0522-49cf-a58e-9ed27d29b99b-image.png
            Or can i emit close signal from one class to another?

            J.HilkJ 1 Reply Last reply
            0
            • D deleted510

              @J-Hilk

              Thanks for the hint!

              Problem is that my class is derived from QWidget.
              0_1561640944704_8fde3df4-0522-49cf-a58e-9ed27d29b99b-image.png
              Or can i emit close signal from one class to another?

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @Stasa-Sekulic
              if you add #include <QGuiApplication> to your class, than you have access to the qApp global pointer of your QGuiApplication instance. You can use that to connect to the signal


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              2
              • D Offline
                D Offline
                deleted510
                wrote on last edited by
                #7

                @J-Hilk

                Thanks! I have implemented everything that you said and IT WORKS!

                I summary i have done next:

                I have connected my QCoreApplication with my widget like this
                connect(QCoreApplication::instance(), SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(state_changed_event(Qt::ApplicationState)));

                and inside my state_changed_event slot i am handling state when application is suspended.

                Main idea was to handle force closure of application from background, i suppose this is not the correct solution, but this workaround is handling that ok for now.

                1 Reply Last reply
                1

                • Login

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