Serial communication stops when window is hidden or minimized on Mac
-
I have a qt application using an instance of QSerialPort in a separate thread. The thread has its own event loop and I use QSerialPort asynchronously (i.e. no blocking calls, only signals and slots). The application works as expected on Windows and Linux, but serial communication stops after a while on Mac when the window is hidden or minimized. If I keep the application minimized it receives and sends few bytes from time to time. When the application has focus again, communication starts again as expected.
I have almost no experience with Mac applications, but I've seen the same behavior in other applications using serial communication. I haven't found much on the web, so event tips on how to search documentation on this issue is highly appreciated :-)
-
Hi and welcome to devnet,
That's likely because of macOS's App Nap facility.
See this GitHub page about that subject and Qt.
-
QSerialPort relies on QSocketNotifier class. If a problem is in "App Nap" then all classes using QSocketNotifier (I guess) becomes unworked (as QAbstractSocket and so on).
PS: If to be honet, I'm not faced with this issue before.
-
Thank you both very much for your help. I had a suspect that the problem was related to power saving because when on AC the problem was still present but intervals with no communication were shorter. Unfortunately I won't be able to test the solution in the linked page before a week or so. I will read something about App Nap in the meanwhile, now that I know what to look for :-)