UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Catching close events in QML or C++

    Scheduled Pinned Locked Moved Solved App Development
    10 Posts 3 Posters 2.9k Views 2 Watching
    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.
      • s710S Offline
        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
        • flohackF Offline
          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: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

          s710S 1 Reply Last reply Reply Quote 0
          • s710S Offline
            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
            • flohackF Offline
              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: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

              s710S 1 Reply Last reply Reply Quote 0
              • s710S Offline
                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.

                flohackF 1 Reply Last reply Reply Quote 0
                • flohackF Offline
                  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: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

                  s710S 1 Reply Last reply Reply Quote 0
                  • s710S Offline
                    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
                    • lduboeufL Offline
                      lduboeuf
                      last edited by

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

                      s710S 1 Reply Last reply Reply Quote 0
                      • s710S Offline
                        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
                        • s710S Offline
                          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

                          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                          With your input, this post could be even better πŸ’—

                          Register Login
                          • First post
                            Last post