views:

200

answers:

3

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:

  • Start/stop a windows service
  • Install/uninstall a windows service
+1  A: 

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...)

Caleb Huitt - cjhuitt
+2  A: 

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)

JimDaniel
+1  A: 

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

Mihai Limbășan
Thanks, good to know about this
JimDaniel