Machine Idle time.



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



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



  • 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..!



  • @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." ?)


  • Qt Champions 2018


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.