• QtServiceController
  • QtServiceController Class

    The QtServiceController class allows you to control services from separate applications. More...

    Header: #include <QtServiceController>

    Detailed Description

    QtServiceController provides a collection of functions that lets you install and run a service controlling its execution, as well as query its status.

    In order to run a service, the service must be installed in the system's service database using the install() function. The system will start the service depending on the specified StartupType; it can either be started during system startup, or when a process starts it manually.

    Once a service is installed, the service can be run and controlled manually using the start(), stop(), pause(), resume() or sendCommand() functions. You can at any time query for the service's status using the isInstalled() and isRunning() functions, or you can query its properties using the serviceDescription(), serviceFilePath(), serviceName() and startupType() functions. For example:

    MyService service;       \\ which inherits QtService
    QString serviceFilePath;
    
    QtServiceController controller(service.serviceName());
    
    if (controller.install(serviceFilePath))
        controller.start()
    
    if (controller.isRunning())
        QMessageBox::information(this, tr("Service Status"),
                                 tr("The %1 service is started").arg(controller.serviceName()));
    
    ...
    
    controller.stop();
    controller.uninstall();
    }

    An instance of the service controller can only control one single service. To control several services within one application, you must create en equal number of service controllers.

    The QtServiceController destructor neither stops nor uninstalls the associated service. To stop a service the stop() function must be called explicitly. To uninstall a service, you can use the uninstall() function.

    See also QtServiceBase and QtService.