Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Machine Idle time.
QtWS25 Last Chance

Machine Idle time.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 990 Views
  • 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.
  • A Offline
    A Offline
    Amol Mali
    wrote on last edited by
    #1

    How to find out machine idle time using qt c++ ?
    i want to store machine idle duration in database..

    JonBJ 1 Reply Last reply
    0
    • A Amol Mali

      How to find out machine idle time using qt c++ ?
      i want to store machine idle duration in database..

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Amol-Mali
      I do not think Qt will have anything for this. A call to determine "machine idle time" (whatever your definition) is going to be highly OS-specific and require non-generic calls. You also don't say whether you are interested in one OS or need to be cross-platform?

      I suggest you start by Googling for c++ machine idle time and see what you think of the hits. You can incorporate non-Qt C++ code into a Qt application if you find the OS call you wish to use.

      1 Reply Last reply
      3
      • A Offline
        A Offline
        Amol Mali
        wrote on last edited by
        #3

        private:
        QPoint mouseLastPos;
        QTimer *mouseTimer;
        quint32 mouseIdleSeconds;

        mainwindow.cpp - Constructor method
        //Init
        mouseTimer = new QTimer();
        mouseLastPos = QCursor::pos();
        mouseIdleSeconds = 0;

        //Connect and Start
        connect(mouseTimer, SIGNAL(timeout()), this, SLOT(mouseTimerTick()));
        mouseTimer->start(1000);

        mainwindow.cpp - Class body
        void MainWindow::mouseTimerTick()
        {
        QPoint point = QCursor::pos();
        if(point != mouseLastPos)
        mouseIdleSeconds = 0;
        else
        mouseIdleSeconds++;

        mouseLastPos = point;
        
        //Here you could determine whatever to do
        //with the total number of idle seconds.
        

        }
        "Reference taken from stackoverflow."

        this works for me as per my requirement.
        Thank you all..!

        JonBJ 1 Reply Last reply
        1
        • A Amol Mali

          private:
          QPoint mouseLastPos;
          QTimer *mouseTimer;
          quint32 mouseIdleSeconds;

          mainwindow.cpp - Constructor method
          //Init
          mouseTimer = new QTimer();
          mouseLastPos = QCursor::pos();
          mouseIdleSeconds = 0;

          //Connect and Start
          connect(mouseTimer, SIGNAL(timeout()), this, SLOT(mouseTimerTick()));
          mouseTimer->start(1000);

          mainwindow.cpp - Class body
          void MainWindow::mouseTimerTick()
          {
          QPoint point = QCursor::pos();
          if(point != mouseLastPos)
          mouseIdleSeconds = 0;
          else
          mouseIdleSeconds++;

          mouseLastPos = point;
          
          //Here you could determine whatever to do
          //with the total number of idle seconds.
          

          }
          "Reference taken from stackoverflow."

          this works for me as per my requirement.
          Thank you all..!

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Amol-Mali
          I do not see how this has anything to do with "Machine Idle time", but up to you.... (In that light, I wouldn't mind reading whatever you mean by "Reference taken from stackoverflow." ?)

          1 Reply Last reply
          1
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            The KDE API has what you need: https://api.kde.org/frameworks/kidletime/html/index.html

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply
            2

            • Login

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