Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML - Seeking best method to detect user inactivity.
Forum Updated to NodeBB v4.3 + New Features

QML - Seeking best method to detect user inactivity.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
9 Posts 5 Posters 1.6k Views 3 Watching
  • 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.
  • V Offline
    V Offline
    VFCraig
    wrote on 1 Nov 2021, 21:51 last edited by
    #1

    Developing a medical device. My responsibility is to create the UI using QML. If a dialog/settings screen is presented, we want to dismiss it programmatically if there is no user interaction after about 60 seconds. Seems the QML EventFilter is not the same as that available in Qt/C++. If that was the case I could easily create a filter and check for activity, passing along any events that should occur to be processed normally. But the QML EventFilter appears to be restricted to web development and server events, of no interest to our application. (Not looking to do anything with the events at this time, or likely anything in the future except maybe to log that something has happened.)

    Ideally, I a seeking a method that I could include in the 2 base classes for which it would be relevant and dismiss any children if the time allotted expires, or reset the timer if there is activity.

    Thanks in advance for any suggestions.

    J 1 Reply Last reply 2 Nov 2021, 06:13
    0
    • V VFCraig
      1 Nov 2021, 21:51

      Developing a medical device. My responsibility is to create the UI using QML. If a dialog/settings screen is presented, we want to dismiss it programmatically if there is no user interaction after about 60 seconds. Seems the QML EventFilter is not the same as that available in Qt/C++. If that was the case I could easily create a filter and check for activity, passing along any events that should occur to be processed normally. But the QML EventFilter appears to be restricted to web development and server events, of no interest to our application. (Not looking to do anything with the events at this time, or likely anything in the future except maybe to log that something has happened.)

      Ideally, I a seeking a method that I could include in the 2 base classes for which it would be relevant and dismiss any children if the time allotted expires, or reset the timer if there is activity.

      Thanks in advance for any suggestions.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 2 Nov 2021, 06:13 last edited by
      #2

      @VFCraig As far as I know, you can install an event filter on your QApllication (in main.cpp) that should get all input activities independently of it being a QWidget or Qml application


      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
      1
      • V Offline
        V Offline
        VFCraig
        wrote on 2 Nov 2021, 14:39 last edited by
        #3

        Installed an event filter in the QApplication in main.cpp. Monitoring QEvent::InputMethod. Need to send a signal to my QML objects to know that the user is still active. Obviously I am not going to create an instance of QApplication in my QML code, how do I connect to a signal sent from the event filter in QML? (Every example I see involves instantiating an object to do so.)

        I would suspect that QApplication may be exposed to QML in some manner?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          GrecKo
          Qt Champions 2018
          wrote on 2 Nov 2021, 16:16 last edited by
          #4

          Create an ActivityWatcher QObject class with an active property.
          Use it as a an event filter for your QGuiApplication (qGuiApp->installEventFilter(this)).
          Register it as a singleton type to QML.

          V 1 Reply Last reply 3 Nov 2021, 13:07
          2
          • K Offline
            K Offline
            KH-219Design
            wrote on 2 Nov 2021, 17:49 last edited by
            #5

            @VFCraig said in QML - Seeking best method to detect user inactivity.:

            Installed an event filter in the QApplication in main.cpp. Monitoring QEvent::InputMethod.

            I'm not 100% certain, but I fear that QEvent::InputMethod is not going to be the best type to listen for. The name is (possibly) misleading. I think it pertains strictly to IME interaction, such as what is described at: https://www.kdab.com/qt-input-method-depth/

            I think that unless the target computer (and/or target user) is using an IME for entering multibyte characters (Chinese, Japanese, Korean, Indian, etc), I think you may end up never seeing even a single QEvent::InputMethod arrive through your filter.

            You might also try:

                    QEvent::MouseButtonPress,
                    QEvent::MouseButtonRelease,
                    QEvent::KeyPress,
                    QEvent::KeyRelease,
            

            www.219design.com
            Software | Electrical | Mechanical | Product Design

            V 1 Reply Last reply 2 Nov 2021, 19:13
            0
            • K KH-219Design
              2 Nov 2021, 17:49

              @VFCraig said in QML - Seeking best method to detect user inactivity.:

              Installed an event filter in the QApplication in main.cpp. Monitoring QEvent::InputMethod.

              I'm not 100% certain, but I fear that QEvent::InputMethod is not going to be the best type to listen for. The name is (possibly) misleading. I think it pertains strictly to IME interaction, such as what is described at: https://www.kdab.com/qt-input-method-depth/

              I think that unless the target computer (and/or target user) is using an IME for entering multibyte characters (Chinese, Japanese, Korean, Indian, etc), I think you may end up never seeing even a single QEvent::InputMethod arrive through your filter.

              You might also try:

                      QEvent::MouseButtonPress,
                      QEvent::MouseButtonRelease,
                      QEvent::KeyPress,
                      QEvent::KeyRelease,
              
              V Offline
              V Offline
              VFCraig
              wrote on 2 Nov 2021, 19:13 last edited by
              #6

              @KH-219Design I wouldn't be surprised if that is the case. Sure, mouse events, keyboard events, tablet events and wheel events inherit from input events, but why not use a name that sounds like it means the same for something completely different? Just like QML's version of an event filter, nothing to do with the event filter in C++.

              1 Reply Last reply
              0
              • G GrecKo
                2 Nov 2021, 16:16

                Create an ActivityWatcher QObject class with an active property.
                Use it as a an event filter for your QGuiApplication (qGuiApp->installEventFilter(this)).
                Register it as a singleton type to QML.

                V Offline
                V Offline
                VFCraig
                wrote on 3 Nov 2021, 13:07 last edited by
                #7

                @GrecKo Nothing in the QML documentation mentions an, "ActivityWatcher". If this is some 3rd party addition, it is not relevant to this question.

                G 1 Reply Last reply 3 Nov 2021, 14:32
                0
                • F Offline
                  F Offline
                  fcarney
                  wrote on 3 Nov 2021, 14:16 last edited by
                  #8

                  @VFCraig said in QML - Seeking best method to detect user inactivity.:

                  Nothing in the QML documentation mentions an, "ActivityWatcher".

                  You will have to write a QObject based class in c++. Then register it to accept events from the gui event system. Then you can filter those events and fire a signal.

                  Registering it as singleton is just making sure there is only one created.

                  In QML you can bind a function to the signal to do what you want.

                  C++ is a perfectly valid school of magic.

                  1 Reply Last reply
                  0
                  • V VFCraig
                    3 Nov 2021, 13:07

                    @GrecKo Nothing in the QML documentation mentions an, "ActivityWatcher". If this is some 3rd party addition, it is not relevant to this question.

                    G Offline
                    G Offline
                    GrecKo
                    Qt Champions 2018
                    wrote on 3 Nov 2021, 14:32 last edited by
                    #9

                    @VFCraig That was meant as the name of the class you would need to create to watch the events of your application.

                    1 Reply Last reply
                    0

                    1/9

                    1 Nov 2021, 21:51

                    • Login

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