Reputation: 39550
We have an existing C++ application which uses WinAPI (let's call it "SvcApp"). We have another C++ WinAPI application called "MgrApp" which installs and starts "SvcApp" as a Windows service.
However, we'd like to replace "SvcApp" with a Qt application. I may be misinformed, but it seems like it's not possible to use <windows.h>
from a Qt application, so it seems that I can't just copy and paste all the existing code from "MgrApp"... or can I?
To summarize, we need to do the following from our Qt app:
Upvotes: 5
Views: 5122
Reputation: 67556
There's already a solution for that - QtService
.
Documentation here: http://qt.nokia.com/doc/solutions/4/qtservice/
Download here: ftp://ftp.qt.nokia.com/qt/solutions/lgpl/qtservice-2.6-opensource.zip
Upvotes: 10
Reputation: 12703
You definitely can use Windows API (including windows.h) in Qt Applications. Behind the scenes Qt uses the Windows API. The normal way cross-platform Qt apps are handled is by using #ifdef blocks. Qt provides macros like Q_OS_WIN32 and Q_WS_MAC for this purpose. Look through the Qt source code and you will see this method used all over the place.
EDIT: You may also want to look into using the command line utilities for installing/uninstalling and starting/stopping windows services. This way you can just use a QProcess to call it, and not have to delve into the WinAPI (which is always nice)
Upvotes: 2
Reputation: 14941
I don't know specifically about the windows.h header, but in general you can include platform-specific code in any of your Qt program. The program merely ceases to be portable across platforms. (It would usually be a better idea to set the platform-specific part apart in a separate file, but if the whole point of the program is to be a windows service, then...)
Upvotes: 1