1

When a Qt desktop application is running on an inactive desktop, after switching to another user (via the OS's switch user feature), can this be detected in code? I need to check for this condition because I need to disable some functionalities of my application if the desktop is not active. If possible, I'd prefer a pure-Qt solution that works on Windows (>= Vista) and OS X (>= 10.6).

Pat
  • 1,726
  • 11
  • 18
  • 1
    As of Qt 5.7, this is not possible without native code. – jonspaceharper Jul 25 '16 at 10:19
  • I'm using Qt 5.6. I'm not against using native code, just like to avoid it when possible. If required, we still have #ifdef's and such... – Pat Jul 25 '16 at 10:19
  • Checking for the main window leaving focus might be enough – paulm Jul 25 '16 at 10:20
  • @paulm: can't use that approach. It's a systray application and main window is usually closed. – Pat Jul 25 '16 at 10:22
  • 1
    You'd have to do per OS native code instead as already mentioned then – paulm Jul 25 '16 at 10:23
  • I added that as a comment just as an FYI. I don't have a native solution, but figured knowing even the most current Qt version lacks such functionality would be helpful. – jonspaceharper Jul 25 '16 at 10:24
  • propably [session managment](http://doc.qt.io/qt-5/session.html)? – user1810087 Jul 25 '16 at 10:25
  • @paulm: John Harper's comment suggests that it would be possible with Qt < 5.7 – Pat Jul 25 '16 at 10:25
  • 3
    Nope. Not what I meant. :-) – jonspaceharper Jul 25 '16 at 10:26
  • Found a solution on windows in http://stackoverflow.com/questions/14315013/how-to-get-the-active-user-when-multiple-users-are-logged-on-in-windows. For OS X this seems useful as well https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPMultipleUsers/Concepts/UserSwitchNotifications.html – Pat Jul 25 '16 at 11:46
  • " comment suggests that it would be possible with Qt < 5.7" On the contrary. It suggests that it's not implemented in any version up to 5.7. Qt usually doesn't drop that sort of functionality between minor versions. – Kuba hasn't forgotten Monica Jul 25 '16 at 18:31

0 Answers0