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.8k 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.
  • J Offline
    J Offline
    Johan_R28
    wrote on 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.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on 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 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 last edited by
          #8
          This post is deleted!
          1 Reply Last reply
          0
          • S Offline
            S Offline
            Solayer
            wrote on last edited by Solayer
            #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.HilkJ 1 Reply Last reply
            0
            • S Solayer

              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.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on 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
              1
              • J.HilkJ J.Hilk

                @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 last edited by
                #11

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

                J.HilkJ 1 Reply Last reply
                0
                • S Solayer

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

                  J.HilkJ Offline
                  J.HilkJ Offline
                  J.Hilk
                  Moderators
                  wrote on 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
                  1
                  • J.HilkJ J.Hilk

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

                    S Offline
                    S Offline
                    Solayer
                    wrote on last edited by
                    #13

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

                    J.HilkJ 1 Reply Last reply
                    0
                    • S Solayer

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

                      J.HilkJ Offline
                      J.HilkJ Offline
                      J.Hilk
                      Moderators
                      wrote on 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
                      0
                      • J.HilkJ J.Hilk

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

                        S Offline
                        S Offline
                        Solayer
                        wrote on 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