ServiceLoader QML Type
The ServiceLoader element holds an instance of a service object. More...
Properties
- asynchronous : bool
- interfaceName : string
- serviceDescriptor : ServiceDescriptor*
- serviceObject : QObject*
- status : Status
Methods
- string errorString()
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
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.
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.
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.
This property contains the status of the service object. It will be one of the following:
- ServiceLoader.Null - the service is inactive or no service has been set
- ServiceLoader.Ready - the service has been loaded
- ServiceLoader.Loading - the service is currently being loaded
- ServiceLoader.Error - an error occurred while loading the service
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
This method returns a human readable description of the last error.
If the status is not ServiceLoader.Error, errorString() will return an empty string.