[SOLVED] Detecting OS events for app switching (Windows, Mac, Linux) in Qt app? Detecting which application is running?



  • Hello,

    I'm trying to make a cross platform Qt app which can detect when certain applications are run by the user (or already running) on the OS (e.g. Firefox and Google Chrome). It also needs to detect when the user switches focus from one app to another (switching from Firefox to Google Chrome).

    Question 1: I'd assume that the native OS environments have some means of achieving this through its API (e.g. Win32 API). But is there any I can achieve this through a Qt app? Any Qt wrapper class for this?

    Question 2: If I do have to resort to OS specific API or libraries, how exactly will I use that within my Qt app? What type of libraries would I need my Qt project? Will I need some sort of static linking? Or Dynamic linking?

    I'm new to Qt desktop application development and I'm not finding any documentation or examples of how to do this.

    Any help would be greatly appreciated.

    Thanks.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    1: There's no API in Qt for that

    2: That's up to you. You might even have the code directly in your application.

    Development using Qt follows the same principle as developing using any other framework. You only have some additional tools to use but it's nicely wrapped up for you.

    When you are saying to didn't find anything, what are you referring to ? Creating an application ? Building a library ?



  • Thanks @SGaist.

    With respect to #2 above, I wasn't too sure whether C/C++ Win32 header files (like windows.h) are just included by default in Qt 5.2.0 MinGW 32 bit. It seems that they are in fact included and I am hoping I can just use them directly without having to link any extra libraries?

    With respect to documentation/examples : I haven't used this type OS specific event handling before so I didn't really where to start exactly, especially with Qt apps. I will look around and update the thread accordingly when I find something. In the meantime, if anyone knows anything which might narrow down my searching time, feel free to comment :)

    Thanks again.


  • Lifetime Qt Champion

    It will all depend on what functions you will use, Windows.h is an "include everything and anything" kind of header. Don't count on it to be included systematically. When using windows specific function, include it or a more specific header.

    The best place to search for that kind of information is the Microsoft Developer Network (MSDN)



  • Thanks for the info @SGaist. I will edit this thread to be [SOLVED] for now since this is not really Qt specific and as you mentioned, I will be looking for more info at MSDN (and for Mac and Linux respectively).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.