Navigation

    UBports Robot Logo

    UBports Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search

    SOLVED Catching close events in QML or C++

    App Development
    3
    10
    478
    Loading More Posts
    • 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.
    • s710
      s710 last edited by

      Is there a way to get a signal when the user closes an app? (not backgrounding, but complete app close)
      Doesn't matter if its via QML or C++, both would be fine for me.

      1 Reply Last reply Reply Quote 0
      • Flohack
        Flohack last edited by

        Humm lets try the obvious child, how about the destructor of QApplication? See https://stackoverflow.com/questions/4381841/qt-how-to-intercept-the-applications-close-event-if-theres-one πŸ™‚

        My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

        s710 1 Reply Last reply Reply Quote 0
        • s710
          s710 @Flohack last edited by s710

          @flohack And in the destructor of the QApplication, will the QML engine and all the stuff still exist and work?

          [edit] Maybe I should have mentioned that, while C++ is an option, I need to trigger actions in QML, namely stopping MediaPlayer playback.

          1 Reply Last reply Reply Quote 0
          • Flohack
            Flohack last edited by

            Oh well πŸ™‚
            Maybe better then to hook https://doc.qt.io/qt-5/qquickwindow.html#closing ? Or similar, Google will help you out.

            My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

            s710 1 Reply Last reply Reply Quote 0
            • s710
              s710 @Flohack last edited by

              @flohack Yeah well, as I said, I don't have a window. I have a QQuickView or a Ubuntu.Components MainView.
              I have already googled quite a bit and tried several solutions, but none worked, thats why I ask here.

              Flohack 1 Reply Last reply Reply Quote 0
              • Flohack
                Flohack @s710 last edited by

                @s710 Well they should be derived and as such have that event too. Did you try out to subscribe ?

                My languages: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

                s710 1 Reply Last reply Reply Quote 0
                • s710
                  s710 @Flohack last edited by

                  @flohack Yep.

                  qrc:/Main.qml:20:4: Cannot assign to non-existent property "onClosing"
                  
                  1 Reply Last reply Reply Quote 0
                  • lduboeuf
                    lduboeuf last edited by

                    Maybe play with applicationState : see https://stackoverflow.com/questions/50845884/how-to-listen-to-qguiapplicationapplicationstatechanged-signals-directly-in-a

                    s710 1 Reply Last reply Reply Quote 0
                    • s710
                      s710 @lduboeuf last edited by

                      @lduboeuf This works, but it does not provide any info about the app closing. Only active/inactive/hidden/suspended.

                      1 Reply Last reply Reply Quote 0
                      • s710
                        s710 last edited by

                        Got it, after googling even more. Some guy at the QT forum revealed:

                           Connections {
                              target: Qt.application
                        
                              onAboutToQuit: {
                                 audioPlayer.stop()
                              }
                        

                        This works πŸ™‚

                        1 Reply Last reply Reply Quote 6
                        • First post
                          Last post