Home

OFF-SOFT.net

OFF-SOFT.net

This site is support & information site of WEB,and Software. This site might help you that create software or Web Site…perhaps?[:]

Qt (7) How to create Windows Service with Qt.

Published on| May 30th, 2009 | 3 Comments.
Description:
In Qt, Windows of the Service that would be created.
Unix deamon process and system of the Windows Service is provided by the class that wraps. Can be easily created by using the class.

However, the standard in the Qt SDK is not included. From the address above, to download, compile (build) is required to work.

In this article, VC + + 2008 Express You can sample and create an overview of the work environment.


Download: http://www.qtsoftware.com/products/appdev/add-on-products/catalog/4/Utilities/qtservice
※ commercial and GPL / LPGL I have some downloads might not be wrong.

GPL / LPGL for the download from where you have the following comments.
Download Open Source Edition (LGPL):

Let's compile
Unzip the downloaded ZIP file
If the open source version, the names of the following ZIP file.
(Some versions are slightly different. )

1
qtservice-2.6-opensource.zip

Here, for example, the destination ZIP to the directory as you extracted the files of the following, we will talk.
C:\Qt\Qt\service

After thawing, the directory is created as follows.

1
2
3
4
5
6
C:\Qt\Qt\service\buildlib
C:\Qt\Qt\service\doc
C:\Qt\Qt\service\examples
C:\Qt\Qt\service\lib
C:\Qt\Qt\service\src
C:\Qt\Qt\service\tmp


Compile (build)
  1. VC + + 2008 Express Start up menu in the "Visula Studio 2008 Command Prompt" opens a

  2. From the command prompt, navigate to the directory where you unpacked directory
    1
    2
    
    C:\Program Files\Microsoft Visual Studio 9.0\VC> cd C:\Qt\Qt\service
    C:\Qt\Qt\service> 
  3. Specify how to build the library
    - Here, DLL creates a version.
    1
    2
    
    C:\Qt\Qt\service> configure -library
    C:\Qt\Qt\service> 
    - Static if you create a library, without parameters config.bat start.
    - You'll see a confirmation message of the license, we will work to answer it.

  4. Compile the library (building)
    1
    2
    3
    4
    5
    6
    
    C:\Qt\Qt\service> qmake
    C:\Qt\Qt\service> nmake
       :
       :
       :
    C:\Qt\Qt\service> 
    - Always here, qmake conducted, make a start. (I work a few)


And complete, debug version, release, all the samples compile (build) is.

Setting your development environment
My Computer - [Properties] Environmental settings.


Environment variable name Value
PATH Lib environment variable to add the directory path.

Cases)
%path%;C:\Qt\Qt\service\.
- C:\Qt\Qt\service\lib\: Qt - Service Lib (DLL) directories

Here, the path environment variable is set, the PATH system environment variable set. PATH environment variable to note that non-users.

The same is true for the path of Qt library. Service When dealing with all of the path of Qt, the PATH system environment variable set.

After the set, OK button.
We change the variables of the system and reboot the system.


After a reboot, try to run the sample.

Let's run the sample
Service in relation to this sample, there are three.

  • An Interactive Service
    - An example of a simple service on your desktop screen.
  • A simple HTTP Server
    - HTTP is a simple example of server services.
  • A simple Service Controller
    - Registration(install) of the service, run ,stop , and remove(uninstall) to sample.

Here, An Interactive Service, A simple Service Controller Let's use.


Convenience of explanation, and then copy the file to the same directory.
1
2
3
C:\temp> copy C:\Qt\Qt\service\examples\controller\release\controller.exe .
C:\temp> copy C:\Qt\Qt\service\examples\interactive\release\interactive.exe .
C:\temp> 

controller.exe interactive.exe registered with the service (install).
1
2
3
4
5
6
C:\temp> controller.exe -i C:\temp\interactive.exe
 
The service Qt Interactive Service has been installed under: C:\temp\interactive.exe
The service was installed.
 
C:\temp> 

The service was installed. If the output is, OK.
The service was not installed. So, it is an error, please try and verify the input.

Also, try to check the services control panel.

As mentioned above, "Qt Interactive Service" If we can confirm the name of the service is OK.

controller.exe using interactive.exe run.
1
2
3
4
C:\temp> controller.exe "Qt Interactive Service" -s
The service "Qt Interactive Service" was started.
 
C:\temp> 

The service "Qt Interactive Service" was started. If the output is, OK.
The service "Qt Interactive Service" was not started. So, it is an error, please try and verify the input.

Also, the top-left desktop "Service" and only appears in a party label.

If you do not see this screen, so there are some environmental problems, and then suggest that you reconsider.

This service, Vista, Windows 7 does not start. XP, 2000 and please confirm.

Stop using the controller.exe interactive.exe.
1
2
3
4
C:\temp> controller.exe "Qt Interactive Service" -t
The service "Qt Interactive Service" was stopped.
 
C:\temp> 

The service "Qt Interactive Service" was stopped. If the output is, OK.
The service "Qt Interactive Service" was not stopped. So, it is an error, please try and verify the input.

Also, the top-left desktop "Service" on the screen disappeared and I only say party labels.

Remove interactive.exe controller.exe using the service (uninstall).
1
2
3
4
C:\temp> controller.exe "Qt Interactive Service" -u
The service "Qt Interactive Service" was uninstalled.
 
C:\temp> 

The service "Qt Interactive Service" was uninstalled. If the output is, OK.
The service "Qt Interactive Service" was not uninstalled. So, it is an error, please try and verify the input.


Looking at the source code of the sample, about two or three line registration service.
The service, QtService <QApplication> Inherit if the method of preparation, too, is not difficult.
You will see the following document if you see main.cpp and it is confused.

http://doc.trolltech.com/solutions/4/qtservice/index.html


Qt is not whether a drug is to create demand for services, it is easy, no doubt.
Once, I tried to be good.

Comments

3 Comments. “Qt (7) How to create Windows Service with Qt.”


  1. Lwin Htoo Ko
    October 15th, 2010 @ 16:06:12

    I tried to compile the qtservice framework. But after nmake, I got the list of errors.

    I am using Qt4.7, Visual Studio 2008 and Window XP.

    C:\Qt\QtService2.6_1>qmake

    C:\Qt\QtService2.6_1>nmake

    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation. All rights reserved.

    cd buildlib\ && “C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nma
    ke.exe” -f Makefile

    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation. All rights reserved.

    c:\Qt\Qt4.7WinCE\bin\qmake.exe -o Makefile buildlib.pro
    “C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe” -f Makef
    ile.Debug

    Microsoft (R) Program Maintenance Utility Version 9.00.21022.08
    Copyright (C) Microsoft Corporation. All rights reserved.

    cl -c -nologo -Zm200 -Zc:wchar_t- -DDEBUG -D_DEBUG -Zi -MDd -EHs-c- -W3
    -w34100 -w34189 -DUNDER_CE -DWINCE -D_WINDOWS -D_UNICODE -DUNICODE -D_WIN32 -DQT
    _NO_PRINTER -DQT_NO_PRINTDIALOG -DARMV4I -D_ARMV4I_ -Darmv4i -D_ARM_ -DARM -D_M_
    ARM -DARM -D__arm__ -DQ_OS_WINCE_WM -DQT_NO_PRINTER -DQT_NO_PRINTDIALOG -D_WIN32
    _WCE=0x502 -DQT_QTSERVICE_EXPORT -DQT_DLL -DQT_GUI_LIB -DQT_CORE_LIB -DQT_THREAD
    _SUPPORT -DQT_NO_DYNAMIC_CAST -I”..\..\Qt4.7WinCE\include\QtCore” -I”..\..\Qt4.7
    WinCE\include\QtGui” -I”..\..\Qt4.7WinCE\include” -I”..\src” -I”..\..\Qt4.7WinCE
    \include\ActiveQt” -I”debug” -I”..\..\Qt4.7WinCE\mkspecs\default” -Fodebug\ @C:\
    DOCUME~1\user\LOCALS~1\Temp\nm6.tmp
    qtservice_win.cpp
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2260) : error C2
    733: second C linkage of overloaded function ‘InterlockedIncrement’ not allowed
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2258) :
    see declaration of ‘InterlockedIncrement’
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2267) : error C2
    733: second C linkage of overloaded function ‘InterlockedDecrement’ not allowed
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2265) :
    see declaration of ‘InterlockedDecrement’
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2275) : error C2
    733: second C linkage of overloaded function ‘InterlockedExchange’ not allowed
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2272) :
    see declaration of ‘InterlockedExchange’
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2286) : error C2
    733: second C linkage of overloaded function ‘InterlockedExchangeAdd’ not allowe
    d
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2283) :
    see declaration of ‘InterlockedExchangeAdd’
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2295) : error C2
    733: second C linkage of overloaded function ‘InterlockedCompareExchange’ not al
    lowed
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\include\winbase.h(2291) :
    see declaration of ‘InterlockedCompareExchange’
    ..\src\qtservice_win.cpp(718) : error C2065: ‘WM_ENDSESSION’ : undeclared identi
    fier
    NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
    \cl.EXE”‘ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘”C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN
    \nmake.exe”‘ : return code ‘0x2’
    Stop.
    NMAKE : fatal error U1077: ‘cd’ : return code ‘0x2’
    Stop.

    Is there solution for that?

    Thanks

  2. master
    October 15th, 2010 @ 19:48:36

    Hi Ko,
    I could compile qt service 2.6.1 with Qt4.7, Visual Studio 2008 and Window XP.
    You might have problem with your environment , or forget ‘C:QtQtService2.6_1> configure -library’ before ‘qmake’.
    If you want static library, you should do it without parameter ( ex) ‘C:QtQtService2.6_1> configure’ ).

    OK?

  3. weihao.ma
    December 28th, 2010 @ 02:03:48

    hi guy, the InteractiveService app works fine to me, but i can’t debug the code in InteractiveService::start() function, what’s the matter with this problem?

Leave a Reply







  • はてなブックマークへ追加する
  • Facebookでシェアする
  • twitter でつぶやく
  • Google Plusでシェアする
  • Pocketでシェアする
ページトップへ