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. how to detect idle status
Forum Updated to NodeBB v4.3 + New Features

how to detect idle status

Scheduled Pinned Locked Moved Solved QML and Qt Quick
15 Posts 4 Posters 3.6k Views 1 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.
  • S Offline
    S Offline
    Solayer
    wrote on 27 Feb 2020, 10:34 last edited by Solayer
    #1

    hello, im a newbie, i have a question to events in qml.
    how to detect idle status in qml.
    i was sreached but i was not understood.
    can someone can help me and show me a simple example .
    Thank you.

    J O 2 Replies Last reply 27 Feb 2020, 11:18
    0
    • S Solayer
      27 Feb 2020, 10:34

      hello, im a newbie, i have a question to events in qml.
      how to detect idle status in qml.
      i was sreached but i was not understood.
      can someone can help me and show me a simple example .
      Thank you.

      J Offline
      J Offline
      J.Hilk
      Moderators
      wrote on 27 Feb 2020, 11:18 last edited by
      #2

      @Solayer said in how to detect idle status:

      idle

      define that!
      What is an idle program in your mind?


      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.

      S 1 Reply Last reply 27 Feb 2020, 15:22
      3
      • S Solayer
        27 Feb 2020, 10:34

        hello, im a newbie, i have a question to events in qml.
        how to detect idle status in qml.
        i was sreached but i was not understood.
        can someone can help me and show me a simple example .
        Thank you.

        O Offline
        O Offline
        ODБOï
        wrote on 27 Feb 2020, 13:12 last edited by ODБOï
        #3

        @Solayer said in how to detect idle status:

        idle

        Do you mean no user input for X seconds ?

        1 Reply Last reply
        1
        • J J.Hilk
          27 Feb 2020, 11:18

          @Solayer said in how to detect idle status:

          idle

          define that!
          What is an idle program in your mind?

          S Offline
          S Offline
          Solayer
          wrote on 27 Feb 2020, 15:22 last edited by Solayer
          #4

          @J-Hilk sorry, my english's very bad.
          Thank you to reply. I mean don't have any event in my program like press mouse, move mouse... in about 2 minutes.

          @LeLev yes,

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Johan_R28
            wrote on 28 Feb 2020, 13:26 last edited by
            #5

            Hi @Solayer,

            You have to install an event filter in your application, which will restart a timer of the desired timeout each time an user interaction event is received, when timer goes off, it's mean your application is in a "idle status".

            How to create an event filter?
            https://doc.qt.io/qt-5/qobject.html#installEventFilter

            How wait for a desired time in QObject?
            https://doc.qt.io/qt-5/qobject.html#startTimer
            or use a QTimer.

            How to install an event filter in QApplication?

            QApplication app(argc, argv);
            app.installEventFilter(myEventFilter);
            

            Regards,

            1 Reply Last reply
            4
            • J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 28 Feb 2020, 14:02 last edited by
              #6

              @Johan_R28 is absolutely right, an eventFilter is the way to go.

              But because I know how difficult it is to warp one own head around the concept,

              here's a very simple example
              https://github.com/DeiVadder/Topic112043


              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
              5
              • J Offline
                J Offline
                Johan_R28
                wrote on 28 Feb 2020, 14:09 last edited by
                #7

                @J-Hilk Indeed, it's a nice example.

                What a turnkey solution ! ^^

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Solayer
                  wrote on 7 Mar 2020, 04:15 last edited by
                  #8
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    Solayer
                    wrote on 9 Mar 2020, 07:41 last edited by Solayer 3 Sept 2020, 07:54
                    #9

                    hello. it's me again.
                    i have a question to QTimer.
                    when i write like this:

                    fileio.cpp

                    FileIO::FileIO(QObject *parent) : QObject(parent){
                        m_timer.setInterval(5000);
                        connect(&m_timer,&QTimer::timeout, &m_timer, &QTimer::stop);
                        connect(&m_timer,&QTimer::timeout,this,[=](){this->goLockScreen();});
                        m_timer.start();
                    }
                    bool FileIO::eventFilter(QObject *obj, QEvent *event){
                        if (event->type() == QEvent::MouseMove){
                            m_timer.start();
                        }
                        return QObject::eventFilter(obj, event);
                    }
                    void FileIO::goLockScreen(){
                        emit emitTimeOut();
                    //    m_timer.stop();
                        qDebug()<<"test C";
                    }
                    

                    main.qml

                        FileIO{
                            id: file
                            onEmitTimeOut: {
                                console.log("QML")
                            }
                        }
                    

                    output when i don't anything

                    test C
                    test C
                    qml: QML
                    test C
                    test C
                    test C
                    test C
                    

                    but i when i write like this
                    fileio.cpp

                    FileIO::FileIO(QObject *parent) : QObject(parent){
                        m_timer.setInterval(5000);
                        connect(&m_timer,&QTimer::timeout,this,[=](){this->goLockScreen();});
                    }
                    bool FileIO::eventFilter(QObject *obj, QEvent *event){
                        if (event->type() == QEvent::MouseMove){
                            m_timer.start();
                        }
                        return QObject::eventFilter(obj, event);
                    }
                    void FileIO::goLockScreen(){
                        emit emitTimeOut();
                        m_timer.stop();
                        qDebug()<<"test C";
                    }
                    

                    main.qml

                        FileIO{
                            id: file
                            onEmitTimeOut: {
                                console.log("QML")
                            }
                        }
                    

                    output when i move in app, console.log in qml not work

                    test C
                    

                    i don't understang what happend, why when i move mouse in app then m_timer start until timeout then emit signal but qml don't receive.
                    m_timer.start in same scope then working fine.
                    sorry my english very bad.
                    thank you very much @J-Hilk @Johan_R28 when you helped me.

                    J 1 Reply Last reply 9 Mar 2020, 08:36
                    0
                    • S Solayer
                      9 Mar 2020, 07:41

                      hello. it's me again.
                      i have a question to QTimer.
                      when i write like this:

                      fileio.cpp

                      FileIO::FileIO(QObject *parent) : QObject(parent){
                          m_timer.setInterval(5000);
                          connect(&m_timer,&QTimer::timeout, &m_timer, &QTimer::stop);
                          connect(&m_timer,&QTimer::timeout,this,[=](){this->goLockScreen();});
                          m_timer.start();
                      }
                      bool FileIO::eventFilter(QObject *obj, QEvent *event){
                          if (event->type() == QEvent::MouseMove){
                              m_timer.start();
                          }
                          return QObject::eventFilter(obj, event);
                      }
                      void FileIO::goLockScreen(){
                          emit emitTimeOut();
                      //    m_timer.stop();
                          qDebug()<<"test C";
                      }
                      

                      main.qml

                          FileIO{
                              id: file
                              onEmitTimeOut: {
                                  console.log("QML")
                              }
                          }
                      

                      output when i don't anything

                      test C
                      test C
                      qml: QML
                      test C
                      test C
                      test C
                      test C
                      

                      but i when i write like this
                      fileio.cpp

                      FileIO::FileIO(QObject *parent) : QObject(parent){
                          m_timer.setInterval(5000);
                          connect(&m_timer,&QTimer::timeout,this,[=](){this->goLockScreen();});
                      }
                      bool FileIO::eventFilter(QObject *obj, QEvent *event){
                          if (event->type() == QEvent::MouseMove){
                              m_timer.start();
                          }
                          return QObject::eventFilter(obj, event);
                      }
                      void FileIO::goLockScreen(){
                          emit emitTimeOut();
                          m_timer.stop();
                          qDebug()<<"test C";
                      }
                      

                      main.qml

                          FileIO{
                              id: file
                              onEmitTimeOut: {
                                  console.log("QML")
                              }
                          }
                      

                      output when i move in app, console.log in qml not work

                      test C
                      

                      i don't understang what happend, why when i move mouse in app then m_timer start until timeout then emit signal but qml don't receive.
                      m_timer.start in same scope then working fine.
                      sorry my english very bad.
                      thank you very much @J-Hilk @Johan_R28 when you helped me.

                      J Offline
                      J Offline
                      J.Hilk
                      Moderators
                      wrote on 9 Mar 2020, 08:36 last edited by
                      #10

                      @Solayer The problem is (most likely), that your FileIO instance that you use as global event filter is not the same instance as the one in your QML file.

                      You have to connect the FileIO signal inside main with a signal inside your QML file.

                      I'll update the repo when I get the time.


                      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.

                      S 1 Reply Last reply 9 Mar 2020, 09:00
                      1
                      • J J.Hilk
                        9 Mar 2020, 08:36

                        @Solayer The problem is (most likely), that your FileIO instance that you use as global event filter is not the same instance as the one in your QML file.

                        You have to connect the FileIO signal inside main with a signal inside your QML file.

                        I'll update the repo when I get the time.

                        S Offline
                        S Offline
                        Solayer
                        wrote on 9 Mar 2020, 09:00 last edited by
                        #11

                        @J-Hilk thanks you again, i'll wait your example

                        J 1 Reply Last reply 9 Mar 2020, 09:02
                        0
                        • S Solayer
                          9 Mar 2020, 09:00

                          @J-Hilk thanks you again, i'll wait your example

                          J Offline
                          J Offline
                          J.Hilk
                          Moderators
                          wrote on 9 Mar 2020, 09:02 last edited by
                          #12

                          @Solayer
                          patched, link still applies:
                          https://github.com/DeiVadder/Topic112043


                          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.

                          S 1 Reply Last reply 9 Mar 2020, 09:20
                          1
                          • J J.Hilk
                            9 Mar 2020, 09:02

                            @Solayer
                            patched, link still applies:
                            https://github.com/DeiVadder/Topic112043

                            S Offline
                            S Offline
                            Solayer
                            wrote on 9 Mar 2020, 09:20 last edited by
                            #13

                            @J-Hilk sorry, but i don't see what's updated

                            J 1 Reply Last reply 9 Mar 2020, 09:24
                            0
                            • S Solayer
                              9 Mar 2020, 09:20

                              @J-Hilk sorry, but i don't see what's updated

                              J Offline
                              J Offline
                              J.Hilk
                              Moderators
                              wrote on 9 Mar 2020, 09:24 last edited by
                              #14

                              @Solayer You're right, the push failed 😑
                              fixed now


                              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.

                              S 1 Reply Last reply 9 Mar 2020, 09:51
                              0
                              • J J.Hilk
                                9 Mar 2020, 09:24

                                @Solayer You're right, the push failed 😑
                                fixed now

                                S Offline
                                S Offline
                                Solayer
                                wrote on 9 Mar 2020, 09:51 last edited by
                                #15

                                @J-Hilk thanks you very much, that's work

                                1 Reply Last reply
                                0

                                • Login

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