How to check if a program is running, by its name, with Qt (C++).
Will QProcess::pid
do the job? I don't know how to use it. Please suggest.
How to check if a program is running, by its name, with Qt (C++).
Will QProcess::pid
do the job? I don't know how to use it. Please suggest.
enter image description here
A quick and dirty way to do it would be to just check the output of
tasklist
, something like:Using
EnumProcesses
is probably a better way (i.e. more "pure"; certainly more performant), but this may be "good enough" as long as this isn't being called in a big loop or something. The same idea could also be ported to other platforms as well, although obviously the command tool and parsing logic would be different.As far as I know QProcess won't allow you to do that (unless you've spawned the process yourself) and in fact nothing in Qt will. However Win32 API provides a way to achieve what you want through
EnumProcesses
function and a complete example of how to use it is provided at Microsoft website:http://msdn.microsoft.com/en-us/library/ms682623.aspx
To get you need replace PrintProcessNameAndID with the following function: