QInferenceBackendFactory Class
The QInferenceBackendFactory class creates QInferenceBackendStep and QInferenceBackendFlow instances from loaded plugins. More...
| Header: | #include <QInferenceBackendFactory> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS EdgeAi)target_link_libraries(mytarget PRIVATE Qt6::EdgeAi) |
| qmake: | QT += edgeai |
| Inherits: | QObject |
| Status: | Technical Preview |
Public Functions
| QInferenceBackendFactory(const QByteArray &backendOverride, QObject *parent = nullptr) | |
| QInferenceBackendStep * | createBackendStep(QInferenceStep *step, const QString &backend) |
| QInferenceBackendFlow * | createInferenceFlowBackend(QInferenceFlow *parent) |
| QString | defaultBackend() const |
| QString | defaultStepProvider(const QString &category = QStringLiteral("vision")) const |
| void | registerFlowProvider(const QString &backend, QInferenceFlowBackendProvider *provider) |
| void | registerStepProvider(const QString &backend, const QString &category, QInferenceBackendStepProvider *provider) |
| void | registerStepProvider(const QString &backend, const QString &name, const QString &category, QInferenceBackendStepProvider *provider) |
| bool | unregisterFlowProvider(const QString &backend) |
| bool | unregisterStepProvider(const QString &backend, const QString &category) |
| bool | unregisterStepProvider(const QString &backend, const QString &name, const QString &category) |
Static Public Members
| QInferenceBackendFactory * | instance() |
Detailed Description
The factory is a singleton. It loads plugins implementing QInferenceFlowBackendProvider or QInferenceBackendStepProvider from the edgeai subdirectory of the application's library paths, and uses them to create the backend implementations behind QInferenceFlow and the QInferenceStep subclasses.
See also createBackendStep(), createInferenceFlowBackend(), and instance().
Member Function Documentation
[explicit] QInferenceBackendFactory::QInferenceBackendFactory(const QByteArray &backendOverride, QObject *parent = nullptr)
Creates a factory whose defaultBackend() is backendOverride, or the built-in default when that is empty, with the given parent. The singleton returned by instance() is constructed with the value of QT_INFERENCE_FLOW_BACKEND; constructing one directly is useful in tests that want to pin the backend.
QInferenceBackendStep *QInferenceBackendFactory::createBackendStep(QInferenceStep *step, const QString &backend)
Creates a QInferenceBackendStep for step, which is the QInferenceStep that owns the new implementation. The provider is selected within backend, the backend name such as "gstreamer".
A step type that requires a provider, such as QVisionInference with its provider property, gets the provider registered under the name that the step gives. A warning is logged and there is no implementation if the name is empty, or if backend has no provider of that name. A step type that names no provider, such as a video source, gets the provider registered for its category().
Returns the new implementation, or nullptr if no matching provider is available.
step The QInferenceStep that owns this implementation. backend The backend name (e.g. "gstreamer") whose plugin should provide the step.
See also createInferenceFlowBackend(), registerStepProvider(), and QInferenceBackendStepProvider::createBackendStep().
QInferenceBackendFlow *QInferenceBackendFactory::createInferenceFlowBackend(QInferenceFlow *parent)
Creates and returns a new QInferenceBackendFlow from the QInferenceFlowBackendProvider registered for defaultBackend(), or nullptr if no matching provider is available. parent is the QInferenceFlow that will own the backend flow.
See also defaultBackend(), createBackendStep(), and QInferenceFlowBackendProvider::createFlow().
QString QInferenceBackendFactory::defaultBackend() const
Returns the backend name used to create flows and their steps. The value of the QT_INFERENCE_FLOW_BACKEND environment variable takes precedence; if it is unset or empty, the default backend ("gstreamer") is used.
The name is resolved once, when the factory is first used, and every flow and step created afterwards is given the same one. Setting the environment variable later has no effect, which is what keeps a flow and the steps it is built from from ending up on different backends.
See also createInferenceFlowBackend() and createBackendStep().
QString QInferenceBackendFactory::defaultStepProvider(const QString &category = QStringLiteral("vision")) const
Returns the name of the default step provider for steps of category, such as "vision", within defaultBackend(), or an empty string if there is none. Pass the name to a step, such as QVisionInference::provider, to select the provider.
The providers that have a name are considered: those from plugins, and those registered with a name through registerStepProvider(). If several of them create steps of category, the first one in alphabetical order of name is returned, so the result is the same on every run.
See also defaultBackend(), createBackendStep(), and QVisionInference::provider.
[static] QInferenceBackendFactory *QInferenceBackendFactory::instance()
Returns the singleton instance of the factory.
See also createBackendStep() and createInferenceFlowBackend().
void QInferenceBackendFactory::registerFlowProvider(const QString &backend, QInferenceFlowBackendProvider *provider)
Registers provider as the flow backend for backend, replacing any earlier registration under the same name. The factory does not take ownership; provider must outlive the factory's use of it. This complements plugin-based discovery and is primarily useful for supplying a mock backend in tests without loading a plugin.
See also unregisterFlowProvider(), createInferenceFlowBackend(), and defaultBackend().
void QInferenceBackendFactory::registerStepProvider(const QString &backend, const QString &category, QInferenceBackendStepProvider *provider)
Registers provider as the step provider for category within backend, replacing any earlier registration under the same pair. The factory does not take ownership; provider must outlive the factory's use of it. This complements plugin-based discovery and is primarily useful for supplying a mock backend in tests without loading a plugin.
See also unregisterStepProvider(), registerFlowProvider(), and createBackendStep().
void QInferenceBackendFactory::registerStepProvider(const QString &backend, const QString &name, const QString &category, QInferenceBackendStepProvider *provider)
Registers provider as the step provider named name for category within backend, in addition to registering it for the category. A step that names the provider, such as QVisionInference::provider, then gets it, and defaultStepProvider() can return its name. This is how an application adds a step provider of its own, without a plugin. Call it again with the same name and provider to add more categories. Registering name again with another provider replaces the provider, and the categories listed for the name start over from category.
This is an overloaded function.
See also unregisterStepProvider() and defaultStepProvider().
bool QInferenceBackendFactory::unregisterFlowProvider(const QString &backend)
Removes the flow provider registered for backend, so that the factory no longer refers to it. Returns true if a provider was registered for backend, or false if there was nothing to remove.
Because the factory does not own registered providers, a caller that destroys a provider must unregister it first; otherwise the factory is left holding a dangling pointer.
See also registerFlowProvider() and createInferenceFlowBackend().
bool QInferenceBackendFactory::unregisterStepProvider(const QString &backend, const QString &category)
Removes the step provider registered for category within backend, so that the factory no longer refers to it. Returns true if a provider was registered for that pair, or false if there was nothing to remove. When the last category of backend is removed, the backend itself is dropped as well.
If the removed provider is also registered under a name, the name no longer lists category, and the name is removed with its last category. Other providers that list category under their names keep it.
Because the factory does not own registered providers, a caller that destroys a provider must unregister it first; otherwise the factory is left holding a dangling pointer. This function does not remove a provider that was registered under a name and has since been replaced for the category by another provider. To remove it, call unregisterStepProvider(const QString &, const QString &, const QString &) with its name.
See also registerStepProvider() and createBackendStep().
bool QInferenceBackendFactory::unregisterStepProvider(const QString &backend, const QString &name, const QString &category)
Removes category from the step provider registered under name within backend, so that the factory no longer refers to it for the category. The name is removed with its last category, and the provider is also removed as the provider of category if it is the one registered for it. A provider that another provider has replaced for the category stays registered under its name until it is removed here.
Returns true if name listed category, or false if there was nothing to remove.
This is an overloaded function.
See also registerStepProvider().
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.