Home > Mobile >  Is there any api or method in qt to put the device in sleep mode after a specific time if no respons
Is there any api or method in qt to put the device in sleep mode after a specific time if no respons

Time:10-15

I am creating an application for linux and want to put the device screen in sleep mode after a particular time like 5 minutes, 10 minutes etc if no response or event occur by the user side.

CodePudding user response:

I do not think that there is a possibility for qt to do that, because a sleep mode is handled by the desktop environment like GNOME, Xfce, and so on. Qt itself isn't able to do this, but maybe you could a function which just send a command to the os, which has the opportunity to set the system to sleep. Maybe this could help you:

https://linuxer.eu/put-linux-into-sleep-from-command-line/

CodePudding user response:

Piggybacking on the other answer a bit here.

You could install an eventFilter at a top-level in your application to monitor any input events as they occur (whether that be a mouse click or move event, keyboard event, etc.). At the same scope as that eventFilter, you could then use some QTimer with the interval set to your sleep timeout duration, which you restart every time an input occurs. That QTimer's timeout signal could be hooked up to a slot where you put the system to sleep via a QProcess call out to sh for example.

  • Related