Results 1 to 13 of 13

Thread: Start Qt application as Windows Service

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Start Qt application as Windows Service

    Hi,

    I'm trying to start a Qt application with the help of a Windows Service.

    The service gets the exe of the application on Windows Registry and starts it without any window.

    The problem is that the application is not started. I've tryied to change the application that is started fot "cmd.exe" and it starts correctly.

    Is there any problem on starting the application without the main window? -> The application has a main window but the service force it to start without it.

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Start Qt application as Windows Service

    Maybe you have some path related problem?

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    No, the path is correct. I have changed the "cmd.exe" to "myApp.exe" on the app dir and it starts without window. But if "myApp.exe" is really my Qt app it don't work.

    Thanks,
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Start Qt application as Windows Service

    I meant maybe your application needs some files which it can't find and crashes before you have a chance to check it out.

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    The application starts if I start it by double clicking on windows explorer.

    Maybe the application don't recive window events because the service starts the application without the main window?
    Some time ago I programmed an application using MFC and a service that start it as this new application but the MFC application starts without showing the main window and the new Qt application don't start.

    Thanks,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Start Qt application as Windows Service

    Quote Originally Posted by ^NyAw^ View Post
    The application starts if I start it by double clicking on windows explorer.
    This doesn't mean anything. The current working directory might be set differently.

  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    The application try to read a config file but removing all this code and only setuping the gui with "ui.setupUi(this);" don't work.

    I have added a little code on main.cpp that writes "Hello" on a file. It works executing it but not starting by the service.

    Thanks,
    Òscar Llarch i Galán

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Start Qt application as Windows Service

    Try compiling and running a non-Qt app like this one:

    Qt Code:
    1. int main(){
    2. while(1);
    3. return 0;
    4. }
    To copy to clipboard, switch view to plain text mode 

    If it works, try adding a QCoreApplication and then a QApplication. Observe what happens in each.

  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    I compiled the simple application and it starts.
    Then I created a simple Qt console application that uses QCoreApplication and it is not started by the service.

    Thanks,
    Òscar Llarch i Galán

  10. #10
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    I copied the Qt libs on the application dir and the QCoreApplication starts.
    Then I tryied to create a QApplication and it starts.
    Finally tryied my application and starts.
    So, I think that when start the application by a Windows Service, the libs must be on the "system32" dir or on the same dir of the application.

    Thanks wysota,
    Òscar Llarch i Galán

  11. #11
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    The QTDIR path is set as User variable on Windows, so if the service is started as "LocalSystem" it don't have QTDIR path so when try to start my application don't work.

    So one solution could be to set the QTDIR on the Path of the system instead of the path of the current user.
    Second solution is to copy the Qt libs into the "system32" folder where are the system libs.
    Third solution is to copy the Qt libs on the application directory.

    Òscar Llarch i Galán

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Start Qt application as Windows Service

    As I said - a path problem. Your libs must be accessible, regardless of system configuration. The only safe place to put them is system32 directory.

  13. #13
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    69
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Start Qt application as Windows Service

    Hi,

    Thanks for help,
    Òscar Llarch i Galán

Similar Threads

  1. QSkinWindows Classes
    By kernel_panic in forum Qt-based Software
    Replies: 45
    Last Post: 20th April 2010, 13:35
  2. start application: Why this error and how to solve it?
    By Colx007 in forum Qt Programming
    Replies: 1
    Last Post: 21st January 2008, 16:22
  3. Porting Qt embedded application to windows.
    By vipin in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 14th January 2008, 17:08
  4. Replies: 2
    Last Post: 9th June 2007, 20:19
  5. Application plugin on windows
    By Eyee in forum Qt Programming
    Replies: 2
    Last Post: 22nd March 2006, 18:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.