QQmlExtensionPlugin Class

The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins with custom type registration functions. 更多...

头: #include <QQmlExtensionPlugin>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
继承: QObject

公共函数

virtual void unregisterTypes ()

重实现公共函数

virtual void initializeEngine (QQmlEngine * engine , const char * uri ) override
virtual void registerTypes (const char * uri ) override = 0

详细描述

注意: If you need to write a plugin manually (which is rare) you should always use QQmlEngineExtensionPlugin . QQmlExtensionPlugin only provides the registerTypes () 和 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.

成员函数文档编制

[override virtual] void QQmlExtensionPlugin:: initializeEngine ( QQmlEngine * engine , const char * uri )

Initializes the extension from the uri 使用 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, since 6.0] void QQmlExtensionPlugin:: unregisterTypes ()

Override this method to unregister types manually registered in registerTypes .

该函数在 Qt 6.0 引入。