Solved how to detect idle status
-
@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 -
@J-Hilk Indeed, it's a nice example.
What a turnkey solution ! ^^
-
This post is deleted! -
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.cppFileIO::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. -
@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.
-
@J-Hilk thanks you again, i'll wait your example
-
@Solayer
patched, link still applies:
https://github.com/DeiVadder/Topic112043 -
@J-Hilk sorry, but i don't see what's updated
-
@Solayer You're right, the push failed 😑
fixed now -
@J-Hilk thanks you very much, that's work