[Interest] Detecting system power events

Kevin André hyperquantum at gmail.com
Wed Sep 15 18:04:37 CEST 2021


I am developing a client-server music player, and I would like to
detect when the server machine enters sleep mode or when it shuts
down. When those events occur I would like the server to pause/stop
playback, send a notification to all clients that are connected at
that time and then close all open TCP connections.

A shutdown can be detected using the "aboutToQuit" signal, but I could
not find anything regarding sleep. Will I need to write
platform-specific code for this (using QAbstractNativeEventFilter) or
is there a better way?

Ideally I would like to be able to distinguish between a shutdown and
the system going to sleep, so I can send a slightly different
notification to the clients. It is useful to know the difference in
the client, because a shutdown implies a permanent disconnect while
sleep means that the client could try to reconnect to the server again
later as soon as it detects its presence again.

The problem I'm having now is the server machine going to sleep while
the client that is running on another machine remains unaware as long
as it does not try to send some kind of request to the server.



More information about the Interest mailing list