Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install a Windows service using Qt?

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
like image 638
Nick Bolton Avatar asked Dec 29 '09 18:12

Nick Bolton


2 Answers

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

like image 60
Mihai Limbășan Avatar answered Oct 26 '22 23:10

Mihai Limbășan


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)

like image 45
JimDaniel Avatar answered Oct 26 '22 23:10

JimDaniel