Results 1 to 4 of 4

Thread: Problems starting a QtService using QtServiceController

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2010
    Location
    Horten, Norway
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems starting a QtService using QtServiceController

    Problem remains unsolved. Noone seems to want to touch it. Please reply here if one or more of the following is valid:
    * you have the same problem, and you cannot solve it either
    * you had the same problem, but you solved it
    * you see whats wrong with the code
    * you think the code looks ok, "there must be something else"
    * you could perhaps see what's wrong, but you need more information

    have a good weekend everyone!

  2. #2
    Join Date
    Sep 2009
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problems starting a QtService using QtServiceController

    I have similar problem as You Stiander. I use Qt 4.7 and it doesn't see QtServiceController class. I have not found in doc on qt.nokia.com informations about this QtService module in Qt 4.7. It means that it is not support now? So how create program as service and control its cycle from Qt level?

  3. #3
    Join Date
    May 2011
    Location
    near munich
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problems starting a QtService using QtServiceController

    Your CService::start() function shouldn´t be blocking. It is not supposed to be the service´s main function (it took me some time to figure that out...). Using these classes there is no main function. You just get an event loop which you start in your programs main() function using myservice.exec().

    To implement your functionality you have to use an event driven approach (signals and slots). Look at the following example. It writes once a second a string to your applications event log.

    Qt Code:
    1. #ifndef SVCMAIN_H
    2. #define SVCMAIN_H
    3.  
    4. #include <QObject>
    5.  
    6. class SvcMain : public QObject
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit SvcMain(QObject *parent = 0);
    11.  
    12. signals:
    13.  
    14. public slots:
    15. void handleTimerEvent();
    16. };
    17.  
    18. #endif // SVCMAIN_H
    To copy to clipboard, switch view to plain text mode 

    The constructor creates a periodic timer:

    Qt Code:
    1. #include "svcmain.h"
    2. #include <QTimer>
    3. #include "qtservice/qtservice.h"
    4.  
    5. SvcMain::SvcMain(QObject *parent) :
    6. QObject(parent)
    7. {
    8. QTimer *timer = new QTimer(this);
    9. connect(timer, SIGNAL(timeout()), this, SLOT(handleTimerEvent()));
    10. timer->start(1000);
    11. }
    12.  
    13. void SvcMain::handleTimerEvent()
    14. {
    15. QtServiceBase::instance()->logMessage(QString("handleTimerEvent"), QtServiceBase::Information );
    16. }
    To copy to clipboard, switch view to plain text mode 

    Your start() function should look like this:

    Qt Code:
    1. void CService::start()
    2. {
    3. svcmain = new SvcMain();
    4. }
    To copy to clipboard, switch view to plain text mode 

    svcmain is a private member variable:

    Qt Code:
    1. private:
    2. SvcMain* svcmain;
    To copy to clipboard, switch view to plain text mode 

    Look at the examples on how to implement the remaining functions (stop/resume/...).
    Hope this helps.

    Sebastian

Similar Threads

  1. Replies: 0
    Last Post: 1st May 2010, 12:41
  2. QtService on Windows as Non-Interactive
    By stefanadelbert in forum Qt Programming
    Replies: 2
    Last Post: 26th April 2010, 03:27
  3. problems starting process
    By parsito in forum Qt Programming
    Replies: 8
    Last Post: 11th May 2007, 21:32
  4. QtService fails to start
    By a550ee in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2006, 13:34
  5. QtService and GAC loadable dll
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2006, 03:39

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.