Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmlextensionplugin.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant
4
7
8QT_BEGIN_NAMESPACE
9
10/*!
11 \since 5.0
12 \inmodule QtQml
13 \class QQmlExtensionPlugin
14 \brief The QQmlExtensionPlugin class provides an abstract base for custom QML extension plugins
15 with custom type registration functions.
16
17 \ingroup plugins
18
19 \note If you need to write a plugin manually (which is rare) you should always use
20 \l{QQmlEngineExtensionPlugin}. QQmlExtensionPlugin only provides the registerTypes() and
21 unregisterTypes() functions in addition. You should not use them, but rather declare your
22 types with \l{QML_ELEMENT} and friends and have the build system take care of the registration.
23*/
24
25/*!
26 \since 5.14
27 \inmodule QtQml
28 \class QQmlEngineExtensionPlugin
29 \brief The QQmlEngineExtensionPlugin class provides an abstract base for custom QML extension
30 plugins.
31
32 \ingroup plugins
33
34 \include qqmlextensionplugin.qdocinc
35
36 The \l {Writing QML Extensions with C++} tutorial also contains a chapter
37 on creating QML plugins.
38
39 \sa {How to Create Qt Plugins}
40*/
41
42/*!
43 \fn void QQmlExtensionPlugin::registerTypes(const char *uri)
44
45 Registers the QML types in the given \a uri. Subclasses should implement
46 this to call \l qmlRegisterType() for all types which are
47 provided by the extension plugin.
48
49 The \a uri is an identifier for the plugin generated by the QML engine
50 based on the name and path of the extension's plugin library.
51*/
52
53/*!
54 \internal
55*/
56QQmlExtensionPlugin::QQmlExtensionPlugin(QObject *parent)
57#if QT_DEPRECATED_SINCE(6, 3)
58 : QObject(*(new QQmlExtensionPluginPrivate), parent)
59#else
60 : QObject(parent)
61#endif
62{
63}
64
65/*!
66 Constructs a QML extension plugin with the given \a parent.
67
68 Note that this constructor is invoked automatically by the
69 Q_PLUGIN_METADATA() macro, so there is no need for calling it
70 explicitly.
71 */
72QQmlEngineExtensionPlugin::QQmlEngineExtensionPlugin(QObject *parent)
73 : QObject(parent)
74{
75}
76
77
78/*!
79 \internal
80 */
81QQmlExtensionPlugin::~QQmlExtensionPlugin() = default;
82
83/*!
84 \internal
85 */
86QQmlEngineExtensionPlugin::~QQmlEngineExtensionPlugin() = default;
87
88#if QT_DEPRECATED_SINCE(6, 3)
89/*!
90 \since 5.1
91 \internal
92 \deprecated [6.3] This is unnecessary and doesn't work for optional plugins
93 \brief Returns the URL of the directory from which the extension is loaded.
94
95 This is useful when the plugin also needs to load QML files or other
96 assets from the same directory.
97
98 \note You should not need this function. Other files that are part of the
99 module's public interface should be specified accordingly in the build
100 system and qmldir file. The build system makes sure that they end up
101 both in the final module directory, and in the resource file system.
102 You can use the copy from the resource file system in the plugin.
103 Non-QML/JS files private to the plugin can be added to the resource
104 file system manually. However, consider moving all such functionality
105 out of the plugin and making the plugin optional.
106*/
107QUrl QQmlExtensionPlugin::baseUrl() const
108{
109 Q_D(const QQmlExtensionPlugin);
110 return d->baseUrl;
111}
112#endif
113
114/*!
115 \since 6.0
116
117 Override this method to unregister types manually registered in registerTypes.
118*/
119void QQmlExtensionPlugin::unregisterTypes()
120{
121
122}
123
124/*!
125 Initializes the extension from the \a uri using the \a engine. Here an application
126 plugin might, for example, expose some data or objects to QML,
127 as context properties on the engine's root context.
128 */
129void QQmlExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
130{
131 Q_UNUSED(engine);
132 Q_UNUSED(uri);
133}
134
135/*!
136 Initializes the extension from the \a uri using the \a engine. Here an application
137 plugin might, for example, expose some data or objects to QML,
138 as context properties on the engine's root context.
139 */
140void QQmlEngineExtensionPlugin::initializeEngine(QQmlEngine *engine, const char *uri)
141{
142 Q_UNUSED(engine);
143 Q_UNUSED(uri);
144}
145
146/*!
147 \class QQmlExtensionInterface
148 \internal
149 \inmodule QtQml
150*/
151
152/*!
153 \class QQmlTypesExtensionInterface
154 \internal
155 \inmodule QtQml
156*/
157
158/*!
159 \class QQmlEngineExtensionInterface
160 \internal
161 \inmodule QtQml
162*/
163
164
165/*!
166 \macro Q_IMPORT_QML_PLUGIN(PluginName)
167 \since 6.2
168 \relates QQmlEngineExtensionPlugin
169
170 Ensures the plugin whose metadata-declaring plugin extension class is named
171 \a PluginName is linked into static builds. For the modules created using
172 \l qt_add_qml_module, the default plugin extension class name is computed
173 from the QML module URI by replacing dots with underscores, unless the
174 \c CLASS_NAME argument is specified.
175
176 For example:
177 \badcode
178 qt_add_qml_module(myplugin
179 # The plugin extension class name in this case is my_Company_QmlComponents.
180 URI my.Company.QmlComponents
181 ...
182 )
183 \endcode
184
185 \sa Q_IMPORT_PLUGIN
186*/
187
188QT_END_NAMESPACE
189
190#include "moc_qqmlextensionplugin.cpp"