• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Register
  • Login
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 1.8k 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.
    • S Offline
      s710
      last edited by 30 Jul 2021, 08:52

      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
      • F Offline
        flohack
        last edited by 30 Jul 2021, 08:55

        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: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

        S 1 Reply Last reply 30 Jul 2021, 08:59 Reply Quote 0
        • S Offline
          s710 @flohack
          last edited by s710 30 Jul 2021, 08:59

          @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
          • F Offline
            flohack
            last edited by 30 Jul 2021, 09:29

            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: πŸ‡¦πŸ‡Ή πŸ‡©πŸ‡ͺ πŸ‡¬πŸ‡§ πŸ‡ΊπŸ‡Έ

            S 1 Reply Last reply 30 Jul 2021, 09:38 Reply Quote 0
            • S Offline
              s710 @flohack
              last edited by 30 Jul 2021, 09:38

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

              F 1 Reply Last reply 30 Jul 2021, 09:47 Reply Quote 0
              • F Offline
                flohack @s710
                last edited by 30 Jul 2021, 09:47

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

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

                S 1 Reply Last reply 30 Jul 2021, 09:50 Reply Quote 0
                • S Offline
                  s710 @flohack
                  last edited by 30 Jul 2021, 09:50

                  @flohack Yep.

                  qrc:/Main.qml:20:4: Cannot assign to non-existent property "onClosing"
                  
                  1 Reply Last reply Reply Quote 0
                  • L Offline
                    lduboeuf
                    last edited by 30 Jul 2021, 10:36

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

                    S 1 Reply Last reply 30 Jul 2021, 12:27 Reply Quote 0
                    • S Offline
                      s710 @lduboeuf
                      last edited by 30 Jul 2021, 12:27

                      @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
                      • S Offline
                        s710
                        last edited by 30 Jul 2021, 13:43

                        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
                        8 out of 10
                        • First post
                          8/10
                          Last post