QScriptExtensionPlugin Class

The QScriptExtensionPlugin class provides an abstract base for custom QScript extension plugins. More...

Header: #include <QScriptExtensionPlugin>
qmake: QT += script
Since: Qt 4.3
Inherits: QObject and QScriptExtensionInterface

This class was introduced in Qt 4.3.

Public Functions

QScriptExtensionPlugin(QObject *parent = nullptr)
virtual ~QScriptExtensionPlugin()
QScriptValue setupPackage(const QString &key, QScriptEngine *engine) const

Reimplemented Public Functions

virtual void initialize(const QString &key, QScriptEngine *engine) override = 0
virtual QStringList keys() const override = 0

Detailed Description

QScriptExtensionPlugin is a plugin interface that makes it possible to offer extensions that can be loaded dynamically into applications using the QScriptEngine class.

Writing a script extension plugin is achieved by subclassing this base class, reimplementing the pure virtual keys() and initialize() functions, and exporting the class using the Q_PLUGIN_METADATA() macro. See How to Create Qt Plugins for details.

See also QScriptEngine::importExtension() and Creating Qt Script Extensions.

Member Function Documentation

QScriptExtensionPlugin::QScriptExtensionPlugin(QObject *parent = nullptr)

Constructs a script extension plugin with the given parent.

Note that this constructor is invoked automatically by the Q_PLUGIN_METADATA() macro, so there is no need for calling it explicitly.

[virtual] QScriptExtensionPlugin::~QScriptExtensionPlugin()

Destroys the script extension plugin.

Note that Qt destroys a plugin automatically when it is no longer used, so there is no need for calling the destructor explicitly.

[override pure virtual] void QScriptExtensionPlugin::initialize(const QString &key, QScriptEngine *engine)

Initializes the extension specified by key in the given engine. The key must come from the set of keys().

See also keys().

[override pure virtual] QStringList QScriptExtensionPlugin::keys() const

Returns the list of keys this plugin supports.

These keys are usually the names of the "modules" or "packages" that are implemented in the plugin (e.g. com.mycompany.MyProduct).

See also initialize().

QScriptValue QScriptExtensionPlugin::setupPackage(const QString &key, QScriptEngine *engine) const

This function is provided for convenience when reimplementing initialize(). It splits the given key on '.' (dot), and ensures that there's a corresponding path of objects in the environment of the given engine, creating new objects to complete the path if necessary. E.g. if the key is "com.trolltech", after the call to setupPackage() the script expression com.trolltech will evaluate to an object. More specifically, the engine's Global Object will have a property called "com", which in turn has a property called "trolltech".

Use this function to avoid global namespace pollution when installing your extensions in the engine.

See also initialize().

© 2024 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.