QQmlExtensionPlugin Class
The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins with custom type registration functions. More...
Header: | #include <QQmlExtensionPlugin> |
Inherits: | QObject and QQmlExtensionInterface |
Public Functions
QQmlExtensionPlugin(QObject *parent = nullptr) | |
virtual | ~QQmlExtensionPlugin() override |
QUrl | baseUrl() const |
virtual void | unregisterTypes() |
Reimplemented Public Functions
virtual void | initializeEngine(QQmlEngine *engine, const char *uri) override |
virtual void | registerTypes(const char *uri) override = 0 |
Detailed Description
\since
5.0 \inmodule
QtQml
\ingroup
plugins
Note: If you need to write a plugin manually (which is rare) you should always use QQmlEngineExtensionPlugin. QQmlExtensionPlugin only provides the registerTypes() and unregisterTypes() functions in addition. You should not use them, but rather declare your types with QML_ELEMENT and friends and have the build system take care of the registration.
Member Function Documentation
[explicit]
QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent = nullptr)
\internal
[override virtual noexcept]
QQmlExtensionPlugin::~QQmlExtensionPlugin()
\internal
QUrl QQmlExtensionPlugin::baseUrl() const
\since
5.1 \internal
\deprecated
[6.3] This is unnecessary and doesn't work for optional plugins
Returns the URL of the directory from which the extension is loaded.
This is useful when the plugin also needs to load QML files or other assets from the same directory.
Note: You should not need this function. Other files that are part of the module's public interface should be specified accordingly in the build system and qmldir file. The build system makes sure that they end up both in the final module directory, and in the resource file system. You can use the copy from the resource file system in the plugin. Non-QML/JS files private to the plugin can be added to the resource file system manually. However, consider moving all such functionality out of the plugin and making the plugin optional.
[override virtual]
void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
Initializes the extension from the uri using the engine. Here an application plugin might, for example, expose some data or objects to QML, as context properties on the engine's root context.
[override pure virtual]
void QQmlExtensionPlugin::registerTypes(const char *uri)
Registers the QML types in the given uri. Subclasses should implement this to call qmlRegisterType() for all types which are provided by the extension plugin.
The uri is an identifier for the plugin generated by the QML engine based on the name and path of the extension's plugin library.
[virtual]
void QQmlExtensionPlugin::unregisterTypes()
\since
6.0
Override this method to unregister types manually registered in registerTypes.