ServiceLoader QML Type

The ServiceLoader element holds an instance of a service object. More...

Properties

Methods

Detailed Description

The ServiceLoader element is part of the Qt ServiceFramework API and provides a client instance of the service object. This element allows the specification of the Service::interfaceName to locate the default service implemented at this interface.

To request a service more specifically, you can filter available ServiceDescriptors with the ServiceFilter element, and then request service objects based off them.

Either way, the ServiceLoader element will provide you with the QtObject provided by that service interface. You can then use its properties, signals, and slots as defined by its interface.

Example:

 import QtQuick 2.0
 import QtServiceFramework 5.0

 QtObject {
     property alias serviceObject: service.serviceObject //In case you want to expose it upwards
     ServiceLoader {
         interfaceName: "com.qt.nokia.example.interface"
         onStatusChanged: {
             if (status == Service.Ready)
                 foo(serviceObject); //In case you want to do something with it as soon as it loads
             else if (status == Service.Error)
                 errorHandling(errorString()); //In case you want to do error handling.
         }
     }
 }

See also ServiceList.

Property Documentation

asynchronous : bool

If asynchronous is false, then the element will block the main thread until a service object is found or an error occurs. This will skip the Loading status. This is generally not recommended, as blocking the main thread can lead to significant problems with user interface responsiveness.

Default is true.


interfaceName : string

Set this to select a service based off of the interface name. The service name, and service version, will be selected for you if a match is found.


serviceDescriptor : ServiceDescriptor*

Set this to select a specific service. ServiceDescriptors can be obtained from the ServiceFilter element.


serviceObject : QObject*

This property holds an instance of the service object which can be used to make metaobject calls to the service.

serviceObject is only valid when the status property is set to ServiceLoader.Ready. Otherwise, it should be a null reference.


status : Status

This property contains the status of the service object. It will be one of the following:

If you want to do something immediately after the service loads, the recommended route is to monitor this property. For example:

 ServiceLoader {
     onStatusChanged: {
         if (status == ServiceLoader.Ready)
             doStuffWith(serviceObject)
         else if (status == ServiceLoader.Error)
             console.debug(errorString())
     }
 }

Method Documentation

string errorString()

This method returns a human readable description of the last error.

If the status is not ServiceLoader.Error, errorString() will return an empty string.