Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qmlfunctions.qdoc
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \macro QML_ELEMENT
6 \relates QQmlEngine
7
8 Declares the enclosing type or namespace to be available in QML, using its
9 class or namespace name as the QML element name.
10
11 For example, this makes the C++ class \c Slider available as a QML type
12 named \c Slider.
13
14 \code
15 class Slider : public QObject
16 {
17 Q_OBJECT
18 QML_ELEMENT
19 ...
20 }
21 \endcode
22
23 You can use the build system to register the type in the type namespace
24 \e {com.mycompany.qmlcomponents} with major version \c 1.
25 For qmake, specify the following in your project file:
26
27 \badcode
28 CONFIG += qmltypes
29 QML_IMPORT_NAME = com.mycompany.qmlcomponents
30 QML_IMPORT_MAJOR_VERSION = 1
31 \endcode
32
33 With CMake, you pass the URI and version to qt_add_qml_module
34
35 \badcode
36 qt6_add_qml_module(myapp
37 URI com.mycompany.qmlcomponents
38 VERSION 1.0
39 )
40 \endcode
41
42 Once registered, the type can be used in QML by importing the
43 same type namespace and version number:
44
45 \qml
46 import com.mycompany.qmlcomponents 1.0
47
48 Slider {
49 // ...
50 }
51 \endqml
52
53 You can also make namespaces tagged with Q_NAMESPACE available this way, in
54 order to expose any enums tagged with Q_ENUM_NS they contain.
55
56 \b{NOTE:} When classes have the same name but are located in different namespaces using
57 \l QML_ELEMENT on both of them will cause a conflict.
58 Make sure to use \l QML_NAMED_ELEMENT() for one of them instead.
59
60 \include {qualified-class-name.qdocinc} {class name must be qualified}
61
62 \sa {Choosing the Correct Integration Method Between C++ and QML}, QML_NAMED_ELEMENT(),
63 Q_REVISION(), QML_ADDED_IN_MINOR_VERSION()
64*/
65
66/*!
67 \macro QML_NAMED_ELEMENT(name)
68 \relates QQmlEngine
69
70 Declares the enclosing type or namespace to be available in QML, using \a name
71 as the element name. Otherwise behaves the same as QML_ELEMENT.
72
73 \code
74 class SqlEventDatabase : public QObject
75 {
76 Q_OBJECT
77 QML_NAMED_ELEMENT(EventDatabase)
78
79 // ...
80 };
81 \endcode
82
83 \sa {Choosing the Correct Integration Method Between C++ and QML}, QML_ELEMENT
84*/
85
86/*!
87 \macro QML_ANONYMOUS
88 \relates QQmlEngine
89
90 Declares the enclosing type to be available, but anonymous in QML. The type
91 cannot be created or used to declare properties in QML, but when passed from
92 C++, it is recognized. In QML, you can use properties of this type if they
93 are declared in C++.
94
95 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_UNCREATABLE(), QML_INTERFACE
96*/
97
98/*!
99 \macro QML_INTERFACE
100 \relates QQmlEngine
101
102 This macro registers the enclosing C++ type in the QML system as an interface.
103
104 Types registered as an interface in QML should also declare themselves as an
105 interface with the \l {The Meta-Object System}{meta object system}. For
106 example:
107
108 \code
109 struct FooInterface
110 {
111 QML_INTERFACE
112 public:
113 virtual ~FooInterface();
114 virtual void doSomething() = 0;
115 };
116
117 Q_DECLARE_INTERFACE(FooInterface, "org.foo.FooInterface")
118 \endcode
119
120 When registered with QML in this way, they can be used as property types:
121
122 Q_PROPERTY(FooInterface *foo READ foo WRITE setFoo)
123
124 When you assign a \l QObject sub-class to this property, the QML engine does
125 the interface cast to \c FooInterface* automatically.
126
127 Interface types are implicitly anonymous and uncreatable in QML.
128
129 \b{NOTE:} When inheriting from types using QML_INTERFACE, use \l QML_IMPLEMENTS_INTERFACES
130 instead of \l Q_INTERFACES.
131
132 \sa QML_IMPLEMENTS_INTERFACES(), QML_ELEMENT, QML_NAMED_ELEMENT(), QML_UNCREATABLE(), QML_ANONYMOUS
133*/
134
135/*!
136 \macro QML_IMPLEMENTS_INTERFACES(interfaces)
137 \relates QQmlEngine
138
139 This macro tells Qt which QML \a interfaces the class implements.
140 This macro should only be used for interfacing with classes using \l QML_INTERFACE, use \l Q_INTERFACES otherwise.
141 It's required in order for declarative registration via \l QML_ELEMENT to
142 function properly.
143
144 \sa QML_INTERFACE, Q_INTERFACES
145*/
146
147/*!
148 \macro QML_UNCREATABLE(reason)
149 \relates QQmlEngine
150
151 Declares that the enclosing type shall not be creatable from QML. This takes
152 effect if the type is available in QML, by having a \l QML_ELEMENT or
153 \l QML_NAMED_ELEMENT() macro. The \a reason will be emitted as error message if an
154 attempt to create the type from QML is detected.
155
156 Some QML types are implicitly uncreatable, in particular types exposed with
157 \l QML_ANONYMOUS or namespaces exposed with \l QML_ELEMENT or
158 \l QML_NAMED_ELEMENT().
159
160 Since Qt 6.0 you can use "" instead of a reason to use a standard message
161 instead.
162
163 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_ANONYMOUS
164*/
165
166/*!
167 \macro QML_SINGLETON
168 \relates QQmlEngine
169
170 Declares the enclosing type to be a singleton in QML. This only takes effect
171 if the type is a \l Q_OBJECT and is available in QML (by having a
172 \l QML_ELEMENT or \l QML_NAMED_ELEMENT() macro). By default, each QQmlEngine
173 will try to create a singleton instance using either the type's default
174 constructor or a static factory function of the signature
175 \c{T *create(QQmlEngine *, QJSEngine *)} when the type is first accessed.
176 If both do exist and are accessible, the default constructor is preferred.
177 If there is no default constructor and no factory function the singleton is
178 inaccessible. The QML engine generally assumes ownership of the singleton and
179 will delete it when the engine itself is destroyed. You can prevent this by
180 calling QJSEngine::setObjectOwnership() on the singleton.
181
182 In order to declare a default-constructible class as singleton, all you have
183 to do is add \l QML_SINGLETON:
184
185 \code
186 class MySingleton : public QObject
187 {
188 Q_OBJECT
189 QML_ELEMENT
190 QML_SINGLETON
191 // Q_PROPERTY( ... )
192 public:
193 // members, Q_INVOKABLE functions, etc.
194 };
195 \endcode
196
197 If the singleton class is not default-constructible, but you can modify it,
198 you can add a factory function to it, in order to make it accessible:
199
200 \code
201 class MySingleton : public QObject
202 {
203 Q_OBJECT
204 QML_ELEMENT
205 QML_SINGLETON
206 // Q_PROPERTY( ... )
207
208 public:
209 static MySingleton *create(QQmlEngine *qmlEngine, QJSEngine *jsEngine)
210 {
211 MySingleton *result = nullptr;
212 // Create the object using some custom constructor or factory.
213 // The QML engine will assume ownership and delete it, eventually.
214 return result;
215 }
216
217 // members, Q_INVOKABLE functions, etc
218 };
219 \endcode
220
221 If you cannot modify the class and it does not have a default constructor or a
222 suitable factory function, you can provide a \l QML_FOREIGN wrapper to define
223 the factory function:
224
225 \code
226 struct SingletonForeign
227 {
228 Q_GADGET
229 QML_FOREIGN(MySingleton)
230 QML_SINGLETON
231 QML_NAMED_ELEMENT(MySingleton)
232 public:
233
234 static MySingleton *create(QQmlEngine *, QJSEngine *engine)
235 {
236 MySingleton *result = nullptr;
237 // Create the instance using some custom constructor or factory.
238 // The QML engine will assume ownership and delete it, eventually.
239 return result;
240 }
241 };
242 \endcode
243
244 Finally, if you want to provide one specific singleton object, the creation of
245 which you cannot control, you can return that from a factory function. This is
246 a replacement for the \l qmlRegisterSingletonInstance function.
247 If you were calling
248
249 \code
250 qmlRegisterSingletonInstance("MyModule", 1, 0, "MySingleton", myObject);
251 \endcode
252
253 with myObject being of type \c{MySingleton *}, you can do the following
254 instead:
255
256 \code
257 struct SingletonForeign
258 {
259 Q_GADGET
260 QML_FOREIGN(MySingleton)
261 QML_SINGLETON
262 QML_NAMED_ELEMENT(MySingleton)
263 public:
264
265 // Initialize this using myObject where you would previously
266 // call qmlRegisterSingletonInstance().
267 inline static MySingleton *s_singletonInstance = nullptr;
268
269 static MySingleton *create(QQmlEngine *, QJSEngine *engine)
270 {
271 // The instance has to exist before it is used. We cannot replace it.
272 Q_ASSERT(s_singletonInstance);
273
274 // The engine has to have the same thread affinity as the singleton.
275 Q_ASSERT(engine->thread() == s_singletonInstance->thread());
276
277 // There can only be one engine accessing the singleton.
278 if (s_engine)
279 Q_ASSERT(engine == s_engine);
280 else
281 s_engine = engine;
282
283 // Explicitly specify C++ ownership so that the engine doesn't delete
284 // the instance.
285 QJSEngine::setObjectOwnership(s_singletonInstance,
286 QJSEngine::CppOwnership);
287 return s_singletonInstance;
288 }
289
290 private:
291 inline static QJSEngine *s_engine = nullptr;
292 };
293 \endcode
294
295 This way, the pre-existing class \c MySingleton is declared to be a QML
296 singleton, called \c MySingleton. You can specify an instance for it any time
297 before it is used by setting the \c s_singletonInstance member. None of this
298 requires modification of \c MySingleton itself.
299
300 \note This pattern doesn't work if either the singleton is accessed by
301 multiple QML engines, or if the QML engine accessing it has a different thread
302 affinity than the singleton object itself. As shown above, you can check the
303 parameters to the \c create() method for identity and thread affinity of the
304 engine in order to assert on that.
305
306 \sa QML_ELEMENT, QML_NAMED_ELEMENT(),
307 qmlRegisterSingletonInstance(), QQmlEngine::singletonInstance()
308*/
309
310/*!
311 \macro QML_ADDED_IN_MINOR_VERSION(VERSION)
312 \relates QQmlEngine
313
314 Declares that the enclosing type or namespace was added in the specified minor
315 \a VERSION, relative to the module major version. The minor version is assumed
316 to be in line with any revisions given by \l Q_REVISION() macros on methods,
317 slots, or signals, and any REVISION tags on properties declared with
318 \l Q_PROPERTY().
319
320 \l QML_ADDED_IN_MINOR_VERSION() only takes effect if the type or namespace is
321 available in QML, by having a \l QML_ELEMENT, \l QML_NAMED_ELEMENT(),
322 \l QML_ANONYMOUS, or \l QML_INTERFACE macro.
323
324 If the QML module the type belongs to is imported with a lower version than
325 the one determined this way, the QML type is invisible.
326
327 \sa QML_ELEMENT, QML_NAMED_ELEMENT()
328*/
329
330/*!
331 \macro QML_REMOVED_IN_MINOR_VERSION(VERSION)
332 \relates QQmlEngine
333
334 Declares that the enclosing type or namespace was removed in the specified
335 minor \a VERSION, relative to the module major version. This is primarily
336 useful when replacing the implementation of a QML type. If a corresponding
337 \l QML_ADDED_IN_MINOR_VERSION() is present on a different type or namespace of
338 the same QML name, then the removed type is used when importing versions of
339 the module lower than \a VERSION, and the added type is used when importing
340 versions of the module greater or equal \a VERSION.
341
342 \l QML_REMOVED_IN_MINOR_VERSION() only takes effect if type or namespace is
343 available in QML, by having a \l QML_ELEMENT, \l QML_NAMED_ELEMENT(),
344 \l QML_ANONYMOUS, or \l QML_INTERFACE macro.
345
346 \sa QML_ELEMENT, QML_NAMED_ELEMENT()
347*/
348
349/*!
350 \macro QML_EXTRA_VERSION(MAJOR, MINOR)
351 \relates QQmlEngine
352
353 Declare that the type should also be available in version \a{MAJOR}.\a{MINOR}.
354 This can be helpful if a type should be available in multiple major versions.
355
356 Types are automatically registered for:
357 \list
358 \li The major version they were introduced in, see \l{QML_ADDED_IN_VERSION}.
359 \li Any major versions any their members were introduced in.
360 \li The current major version of their module, unless they were
361 \l{QML_REMOVED_IN_VERSION} before that.
362 \endlist
363
364 Notably, they are not automatically registered in any \l{PAST_MAJOR_VERSIONS}
365 between the above. You can use QML_EXTRA_VERSION to manually register your
366 types in further major versions.
367
368 \note Keeping multiple \l{PAST_MAJOR_VERSIONS} around is computationally
369 expensive.
370
371 \sa QML_ELEMENT, QML_ADDED_IN_MINOR_VERSION
372*/
373
374/*!
375 \macro QML_ATTACHED(ATTACHED_TYPE)
376 \relates QQmlEngine
377
378 Declares that the enclosing type attaches \a ATTACHED_TYPE as an
379 \l {Attached Properties and Attached Signal Handlers}
380 {attached property} to other types. This takes effect if the type
381 is exposed to QML using a \l QML_ELEMENT or \l QML_NAMED_ELEMENT() macro.
382
383 \include {qualified-class-name.qdocinc} {class name must be qualified}
384
385 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), qmlAttachedPropertiesObject(),
386 {Providing Attached Properties}
387*/
388
389/*!
390 \macro QML_EXTENDED(EXTENDED_TYPE)
391 \relates QQmlEngine
392
393 Declares that the enclosing type uses \a EXTENDED_TYPE as an extension to
394 provide further properties, methods, and enumerations in QML. This takes
395 effect if the type is exposed to QML using a \l QML_ELEMENT or
396 \l QML_NAMED_ELEMENT() macro.
397
398 \warning Members of \a EXTENDED_TYPE are implicitly treated as FINAL.
399
400 \include {qualified-class-name.qdocinc} {class name must be qualified}
401
402 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_EXTENDED_NAMESPACE(),
403 {Registering Extension Objects}
404*/
405
406/*!
407 \macro QML_EXTENDED_NAMESPACE(EXTENDED_NAMESPACE)
408 \relates QQmlEngine
409
410 Declares that the enclosing type uses \a EXTENDED_NAMESPACE as an extension to
411 provide further enumerations in QML. This takes effect if the type
412 is exposed to QML using a \l QML_ELEMENT or \l QML_NAMED_ELEMENT() macro.
413 The enumerations need to be exposed to the metaobject system for this to work.
414
415 For example, give the following C++ code
416 \code
417 namespace MyNamespace {
418 Q_NAMESPACE
419 enum MyEnum { MyEnumerator = 10 };
420 Q_ENUM_NS(MyEnum)
421 }
422
423 class QmlType : public QObject
424 {
425 Q_OBJECT
426 QML_ELEMENT
427 QML_EXTENDED_NAMESPACE(MyNamespace)
428 }
429 \endcode
430
431 we can access the enum in QML:
432 \qml
433 QmlType {
434 property int i: QmlType.MyEnumerator // i will be 10
435 }
436 \endqml
437
438 \note EXTENDED_NAMESPACE can also be a QObject or QGadget; in that case - and in contrast to
439 QML_EXTENDED, which also exposes methods and properties - only its enumerations
440 are exposed.
441
442 \note \a EXTENDED_NAMESPACE must have a metaobject; i.e. it must either be a namespace which
443 contains the Q_NAMESPACE macro or a QObject/QGadget.
444
445 \include {qualified-class-name.qdocinc} {class name must be qualified}
446
447 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_EXTENDED(),
448 {Registering Extension Objects}, Q_ENUM, Q_ENUM_NS
449*/
450
451/*!
452 \macro QML_FOREIGN(FOREIGN_TYPE)
453 \relates QQmlEngine
454
455 Declares that any \l QML_ELEMENT, \l QML_NAMED_ELEMENT(), \l QML_ANONYMOUS,
456 \l QML_INTERFACE, \l QML_UNCREATABLE(), \l QML_SINGLETON,
457 \l QML_ADDED_IN_MINOR_VERSION(), \l QML_REMOVED_IN_MINOR_VERSION(),
458 \l QML_ATTACHED(), \l QML_EXTENDED(), or \l QML_EXTENDED_NAMESPACE() macros
459 in the enclosing C++ type do not apply to the enclosing type but instead to
460 \a FOREIGN_TYPE. The enclosing type still needs to be registered with the
461 \l {The Meta-Object System}{meta object system} using a \l Q_GADGET or
462 \l Q_OBJECT macro.
463
464 This is useful for registering types that cannot be amended to add the macros,
465 for example because they belong to 3rdparty libraries.
466 To register a namespace, see \l QML_FOREIGN_NAMESPACE().
467
468 \b{NOTE:} You may want to use \l QML_NAMED_ELEMENT() instead of \l QML_ELEMENT due to the fact that
469 the element will be named like the struct it is contained in, not the foreign type.
470 See the \l {Extension Objects} for an example.
471
472 \include {qualified-class-name.qdocinc} {class name must be qualified}
473
474 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_FOREIGN_NAMESPACE()
475*/
476
477/*!
478 \macro QML_FOREIGN_NAMESPACE(FOREIGN_NAMESPACE)
479 \relates QQmlEngine
480
481 Declares that any \l QML_ELEMENT, \l QML_NAMED_ELEMENT(), \l QML_ANONYMOUS,
482 \l QML_INTERFACE, \l QML_UNCREATABLE(), \l QML_SINGLETON,
483 \l QML_ADDED_IN_MINOR_VERSION(), or \l QML_REMOVED_IN_MINOR_VERSION()
484 macros in the enclosing C++ namespace do not apply to the enclosing type but
485 instead to \a FOREIGN_NAMESPACE. The enclosing namespace still needs to be
486 registered with the \l {The Meta-Object System}{meta object system} using a
487 \l Q_NAMESPACE macro.
488
489 This is useful for registering namespaces that cannot be amended to add the macros,
490 for example because they belong to 3rdparty libraries.
491
492 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_FOREIGN()
493*/
494
495/*!
496 \macro QML_UNAVAILABLE
497 \relates QQmlEngine
498
499 This macro declares the enclosing type to be unavailable in QML. It registers
500 an internal dummy type called \c QQmlTypeNotAvailable as \l QML_FOREIGN()
501 type, using any further QML macros you specify.
502
503 Normally, the types exported by a module should be fixed. However, if a C++
504 type is not available, you should at least "reserve" the QML type name, and
505 give the user of the unavailable type a meaningful error message.
506
507 Example:
508
509 \code
510 #ifdef NO_GAMES_ALLOWED
511 struct MinehuntGame
512 {
513 Q_GADGET
514 QML_NAMED_ELEMENT(Game)
515 QML_UNAVAILABLE
516 QML_UNCREATABLE("Get back to work, slacker!");
517 };
518 #else
519 class MinehuntGame : public QObject
520 {
521 Q_OBJECT
522 QML_NAMED_ELEMENT(Game)
523 // ...
524 };
525 #endif
526 \endcode
527
528 This will cause any QML which attempts to use the "Game" type to produce an
529 error message:
530
531 \badcode
532 fun.qml: Get back to work, slacker!
533 Game {
534 ^
535 \endcode
536
537 Using this technique, you only need a \l Q_GADGET struct to customize the error
538 message, not a full-blown \l QObject. Without \l QML_UNCREATABLE(),
539 \l QML_UNAVAILABLE still results in a more specific error message than the usual
540 "is not a type" for completely unknown types.
541
542 \include {qualified-class-name.qdocinc} {class name must be qualified}
543
544 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_UNCREATABLE(), QML_FOREIGN()
545*/
546
547/*!
548 \macro QML_SEQUENTIAL_CONTAINER(VALUE_TYPE)
549 \relates QQmlEngine
550
551 This macro declares the enclosing or referenced type as a sequential container
552 managing a sequence of \a VALUE_TYPE elements. \a VALUE_TYPE can be an actual
553 \l{QML Value Types}{value type} or a pointer to an
554 \l{QML Object Types}{object type}. You will rarely be able to add this macro
555 to the actual container declaration since containers are usually templates.
556 You should use \l{QML_FOREIGN} to attach the type registration to a template
557 instantiation. Using this technique you can, for example, declare sequential
558 containers like this:
559
560 \code
561 class IntDequeRegistration
562 {
563 Q_GADGET
564 QML_FOREIGN(std::deque<int>)
565 QML_ANONYMOUS
566 QML_SEQUENTIAL_CONTAINER(int)
567 };
568 \endcode
569
570 After this, you can use the container like a JavaScript array in QML.
571
572 \code
573 class Maze
574 {
575 Q_OBJECT
576 Q_ELEMENT
577 // 0: North, 1: East, 2: South, 3: West
578 Q_PROPERTY(std::deque<int> solution READ solution CONSTANT FINAL)
579 [...]
580 }
581 \endcode
582
583 \code
584 Item {
585 Maze {
586 id: maze
587 }
588
589 function showSolution() {
590 maze.solution.forEach([...])
591 }
592 }
593 \endcode
594
595 \note For \l{QML Value Types} \l{QList} is automatically registered as
596 sequential container. For \l{QML Object Types} \l{QQmlListProperty} is.
597 You don't have to add these registrations.
598
599 \note You cannot currently give the container a custom name. Any argument
600 passed to \l{QML_NAMED_ELEMENT} is ignored. The automatically registered
601 sequential containers are available under the familiar \e{list<...>} names,
602 for example \e{list<QtObject>} or \e{list<font>}.
603
604 \include {qualified-class-name.qdocinc} {class name must be qualified}
605
606 \sa QML_ANONYMOUS, QML_FOREIGN()
607*/
608
609/*!
610 \macro QML_DECLARE_TYPE()
611 \relates QQmlEngine
612
613 Equivalent to \c Q_DECLARE_METATYPE(TYPE *) and \c Q_DECLARE_METATYPE(QQmlListProperty<TYPE>)
614*/
615
616/*!
617 \macro QML_DECLARE_TYPEINFO(Type,Flags)
618 \relates QQmlEngine
619
620 Declares additional properties of the given \a Type as described by the
621 specified \a Flags.
622
623 Current the only supported type info is \c QML_HAS_ATTACHED_PROPERTIES which
624 declares that the \a Type supports \l {Attached Properties and Attached Signal Handlers}
625 {attached properties}. QML_DECLARE_TYPEINFO() is not necessary if \a Type contains the
626 QML_ATTACHED macro.
627*/
628
629/*!
630 \fn void qmlClearTypeRegistrations()
631 \relates QQmlEngine
632
633 Clears all stored type registrations, such as those produced with \l qmlRegisterType().
634
635 Do not call this function while a QQmlEngine exists or behavior will be undefined.
636 Any existing QQmlEngines must be deleted before calling this function. This function
637 only affects the application global cache. Delete the QQmlEngine to clear all cached
638 data relating to that engine.
639*/
640
641
642/*!
643 \fn int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
644 \relates QQmlEngine
645
646 This template function registers the C++ type in the QML system with
647 the name \a qmlName, in the library imported from \a uri having the
648 version number composed from \a versionMajor and \a versionMinor.
649
650 Returns the QML type id.
651
652 There are two forms of this template function:
653
654 \code
655 template<typename T>
656 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
657
658 template<typename T, int metaObjectRevision>
659 int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
660 \endcode
661
662 The former is the standard form which registers the type \e T as a new type.
663 The latter allows a particular revision of a class to be registered in
664 a specified version (see \l {Type Revisions and Versions}).
665
666
667 For example, this registers a C++ class \c MySliderItem as a QML type
668 named \c Slider for version 1.0 of a type namespace called
669 "com.mycompany.qmlcomponents":
670
671 \code
672 qmlRegisterType<MySliderItem>("com.mycompany.qmlcomponents", 1, 0, "Slider");
673 \endcode
674
675 Once this is registered, the type can be used in QML by importing the
676 specified type namespace and version number:
677
678 \qml
679 import com.mycompany.qmlcomponents 1.0
680
681 Slider {
682 // ...
683 }
684 \endqml
685
686 Note that it's perfectly reasonable for a library to register types to older versions
687 than the actual version of the library. Indeed, it is normal for the new library to allow
688 QML written to previous versions to continue to work, even if more advanced versions of
689 some of its types are available.
690
691 \sa QML_ELEMENT, QML_NAMED_ELEMENT(),
692 {Choosing the Correct Integration Method Between C++ and QML}
693*/
694
695/*!
696 \fn int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor)
697 \relates QQmlEngine
698
699 This template function registers the specified revision of a C++ type in the QML system with
700 the library imported from \a uri having the version number composed
701 from \a versionMajor and \a versionMinor.
702
703 Returns the QML type id.
704
705 \code
706 template<typename T, int metaObjectRevision>
707 int qmlRegisterRevision(const char *uri, int versionMajor, int versionMinor);
708 \endcode
709
710 This function is typically used to register the revision of a base class to
711 use for the specified version of the type (see \l {Type Revisions and Versions}).
712*/
713
714/*!
715 \fn int qmlRegisterUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message)
716 \relates QQmlEngine
717
718 This template function registers the C++ type in the QML system with
719 the name \a qmlName, in the library imported from \a uri having the
720 version number composed from \a versionMajor and \a versionMinor.
721
722 While the type has a name and a type, it cannot be created, and the
723 given error \a message will result if creation is attempted.
724
725 This is useful where the type is only intended for providing attached properties or enum values.
726
727 Returns the QML type id.
728
729 \sa QML_UNCREATABLE(), qmlRegisterTypeNotAvailable(),
730 {Choosing the Correct Integration Method Between C++ and QML}
731*/
732
733/*!
734 \fn int qmlRegisterExtendedType(const char *uri, int versionMajor, int versionMinor, const char *qmlName)
735 \relates QQmlEngine
736
737 This template function registers the C++ type and its extension object in the
738 QML system with the name \a qmlName in the library imported from \a uri having
739 version number composed from \a versionMajor and \a versionMinor. Properties
740 not available in the main type will be searched for in the extension object.
741
742 Returns the QML type id.
743
744 \sa QML_EXTENDED(), qmlRegisterType(), {Registering Extension Objects}
745*/
746
747
748/*!
749 \fn int qmlRegisterExtendedUncreatableType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
750 \relates QQmlEngine
751
752 This template function registers the C++ type and its extension
753 in the QML system with the name \a qmlName in the library imported
754 from \a uri having version number composed from \a versionMajor and
755 \a versionMinor.
756
757 While the type has a name and a type, it cannot be created. An error
758 message with the given \a reason is printed if the user attempts to
759 create an instance of this type.
760
761 This is useful where the type is only intended for providing attached
762 properties, enum values or an abstract base class with its extension.
763
764 Returns the QML type id.
765
766 \sa QML_EXTENDED(), QML_UNCREATABLE(), qmlRegisterUncreatableType()
767*/
768
769/*!
770 \fn static inline int qmlRegisterUncreatableMetaObject(const QMetaObject &staticMetaObject, const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& reason)
771 \relates QQmlEngine
772 \since 5.8
773
774 This function registers the \a staticMetaObject and its extension
775 in the QML system with the name \a qmlName in the library imported
776 from \a uri having version number composed from \a versionMajor and
777 \a versionMinor.
778
779 An instance of the meta object cannot be created. An error message with
780 the given \a reason is printed if the user attempts to create it.
781
782 This function is useful for registering Q_NAMESPACE namespaces.
783
784 Returns the QML type id.
785
786 For example:
787
788 \code
789 namespace MyNamespace {
790 Q_NAMESPACE
791 enum MyEnum {
792 Key1,
793 Key2,
794 };
795 Q_ENUM(MyEnum)
796 }
797
798 //...
799 qmlRegisterUncreatableMetaObject(MyNamespace::staticMetaObject, "io.qt", 1, 0, "MyNamespace", "Access to enums & flags only");
800 \endcode
801
802 On the QML side, you can now use the registered enums:
803 \code
804 Component.onCompleted: console.log(MyNamespace.Key2)
805 \endcode
806
807 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_UNCREATABLE()
808*/
809
810/*!
811 \fn int qmlRegisterCustomExtendedType(const char *uri, int versionMajor, int versionMinor, const char *qmlName, QQmlCustomParser *parser)
812 \relates QQmlEngine
813 \internal
814
815 This template function registers the C++ type and its extension
816 in the QML system with the name \a qmlName in the library imported
817 from \a uri having version number composed from \a versionMajor and
818 \a versionMinor. Properties from the C++ type or its extension that
819 cannot be resolved directly by the QML system will be resolved using
820 the \a parser provided.
821
822 Returns the QML type id.
823
824 \sa QML_ELEMENT, QML_NAMED_ELEMENT(), QML_EXTENDED()
825*/
826
827/*!
828 \fn int qmlRegisterTypeNotAvailable(const char *uri, int versionMajor, int versionMinor, const char *qmlName, const QString& message)
829 \relates QQmlEngine
830
831 This function registers a type in the QML system with the name \a qmlName, in the type namespace imported from \a uri having the
832 version number composed from \a versionMajor and \a versionMinor, but any attempt to instantiate the type
833 will produce the given error \a message.
834
835 Normally, the types exported by a plugin should be fixed. However, if a C++ type is not available, you should
836 at least "reserve" the QML type name, and give the user of the unavailable type a meaningful error message.
837
838 Returns the QML type id.
839
840 Example:
841
842 \code
843 #ifdef NO_GAMES_ALLOWED
844 qmlRegisterTypeNotAvailable("MinehuntCore", 0, 1, "Game", "Get back to work, slacker!");
845 #else
846 qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game");
847 #endif
848 \endcode
849
850 This will cause any QML which imports the "MinehuntCore" type namespace and attempts to use the type to produce an error message:
851 \code
852 fun.qml: Get back to work, slacker!
853 Game {
854 ^
855 \endcode
856
857 Without this, a generic "Game is not a type" message would be given.
858
859 \sa QML_UNAVAILABLE, qmlRegisterUncreatableType(),
860 {Choosing the Correct Integration Method Between C++ and QML}
861*/
862
863/*!
864 \fn int qmlRegisterAnonymousType(const char *uri, int versionMajor)
865 \relates QQmlEngine
866
867 This template function registers the C++ type in the QML system as an anonymous type. The
868 resulting QML type does not have a name. Therefore, instances of this type cannot be created from
869 the QML system. You can, however, access instances of the type when they are exposed as properties
870 of other types.
871
872 Use this function when the type will not be referenced by name, specifically for C++ types that
873 are used on the left-hand side of a property binding. To indicate to which module the type belongs
874 use \a uri and \a versionMajor.
875
876 For example, consider the following two classes:
877
878 \code
879 class Bar : public QObject
880 {
881 Q_OBJECT
882 Q_PROPERTY(QString baz READ baz WRITE setBaz NOTIFY bazChanged)
883
884 public:
885 Bar() {}
886
887 QString baz() const { return mBaz; }
888
889 void setBaz(const QString &baz)
890 {
891 if (baz == mBaz)
892 return;
893
894 mBaz = baz;
895 emit bazChanged();
896 }
897
898 signals:
899 void bazChanged();
900
901 private:
902 QString mBaz;
903 };
904
905 class Foo : public QObject
906 {
907 Q_OBJECT
908 Q_PROPERTY(Bar *bar READ bar CONSTANT FINAL)
909
910 public:
911 Foo() {}
912
913 Bar *bar() { return &mBar; }
914
915 private:
916 Bar mBar;
917 };
918 \endcode
919
920 In QML, we assign a string to the \c baz property of \c bar:
921
922 \code
923 Foo {
924 bar.baz: "abc"
925 Component.onCompleted: print(bar.baz)
926 }
927 \endcode
928
929 For the QML engine to know that the \c Bar type has a \c baz property,
930 we have to make \c Bar known:
931
932 \code
933 qmlRegisterType<Foo>("App", 1, 0, "Foo");
934 qmlRegisterAnonymousType<Bar>("App", 1);
935 \endcode
936
937 As the \c Foo type is instantiated in QML, it must be registered
938 with the version of \l qmlRegisterType() that takes an element name.
939
940 Returns the QML type id.
941
942 \since 5.14
943 \sa QML_ANONYMOUS, {Choosing the Correct Integration Method Between C++ and QML}
944*/
945
946/*!
947 \fn int qmlRegisterInterface(const char *typeName)
948 \relates QQmlEngine
949
950 This template function registers the C++ type in the QML system
951 under the name \a typeName.
952
953 Types registered as an interface with the engine should also
954 declare themselves as an interface with the
955 \l {The Meta-Object System}{meta object system}. For example:
956
957 \code
958 struct FooInterface
959 {
960 public:
961 virtual ~FooInterface();
962 virtual void doSomething() = 0;
963 };
964
965 Q_DECLARE_INTERFACE(FooInterface, "org.foo.FooInterface")
966 \endcode
967
968 When registered with the QML engine in this way, they can be used as
969 property types:
970
971 Q_PROPERTY(FooInterface *foo READ foo WRITE setFoo)
972
973 When you assign a \l QObject sub-class to this property, the QML engine does
974 the interface cast to \c FooInterface* automatically.
975
976 Returns the QML type id.
977
978 \sa QML_INTERFACE
979*/
980
981/*!
982 \fn int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, QJSValue (*callback)(QQmlEngine *, QJSEngine *))
983 \relates QQmlEngine
984
985 This function may be used to register a singleton type provider \a callback in a particular \a uri
986 and \a typeName with a version specified in \a versionMajor and \a versionMinor.
987
988 Installing a singleton type allows developers to provide arbitrary functionality
989 (methods and properties) to a client without requiring individual instances of the type to
990 be instantiated by the client.
991
992 A singleton type may be either a QObject or a QJSValue.
993 This function should be used to register a singleton type provider function which returns a QJSValue as a singleton type.
994
995 \b{NOTE:} QJSValue singleton type properties will \b{not} trigger binding re-evaluation if changed.
996
997 Usage:
998 \code
999 // First, define the singleton type provider function (callback).
1000 static QJSValue example_qjsvalue_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
1001 {
1002 Q_UNUSED(engine)
1003
1004 static int seedValue = 5;
1005 QJSValue example = scriptEngine->newObject();
1006 example.setProperty("someProperty", seedValue++);
1007 return example;
1008 }
1009
1010 // Second, register the singleton type provider with QML by calling this function in an initialization function.
1011 qmlRegisterSingletonType("Qt.example.qjsvalueApi", 1, 0, "MyApi", example_qjsvalue_singletontype_provider);
1012 \endcode
1013
1014 Alternatively, you can use a C++11 lambda:
1015
1016 \code
1017 qmlRegisterSingletonType("Qt.example.qjsvalueApi", 1, 0, "MyApi", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QJSValue {
1018 Q_UNUSED(engine)
1019
1020 static int seedValue = 5;
1021 QJSValue example = scriptEngine->newObject();
1022 example.setProperty("someProperty", seedValue++);
1023 return example;
1024 });
1025 \endcode
1026
1027 In order to use the registered singleton type in QML, you must import the singleton type.
1028 \qml
1029 import QtQuick 2.0
1030 import Qt.example.qjsvalueApi 1.0 as ExampleApi
1031 Item {
1032 id: root
1033 property int someValue: ExampleApi.MyApi.someProperty
1034 }
1035 \endqml
1036
1037 \sa QML_SINGLETON, {Choosing the Correct Integration Method Between C++ and QML}
1038*/
1039
1040/*!
1041 \fn template<typename T> QObject *qmlAttachedPropertiesObject(const QObject *attachee, bool create)
1042 \relates QQmlEngine
1043
1044 The form of this template function is:
1045
1046 \code
1047 template<typename T> QObject *qmlAttachedPropertiesObject(const QObject *attachee, bool create = true)
1048 \endcode
1049
1050 This returns the attached object instance that has been attached to the specified
1051 \a attachee by the attaching type \e T.
1052
1053 If \a create is true and type \e T is a valid attaching type, this creates and returns a new
1054 attached object instance.
1055
1056 Returns \nullptr if type \e T is not a valid attaching type, or if \a create is false and no
1057 attachment object instance has previously been created for \a attachee.
1058
1059 \sa QML_ATTACHED(), {Providing Attached Properties}
1060*/
1061
1062/*!
1063 \fn QObject *qmlExtendedObject(const QObject *base)
1064 \relates QQmlEngine
1065
1066 This function returns the extension object that belongs to \a base, if there is any.
1067 Otherwise it returns \c nullptr.
1068
1069 \sa QML_EXTENDED
1070*/
1071
1072/*!
1073 \fn int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, QObject *(*callback)(QQmlEngine *, QJSEngine *))
1074 \relates QQmlEngine
1075
1076 This function may be used to register a singleton type provider \a callback in a particular \a uri
1077 and \a typeName with a version specified in \a versionMajor and \a versionMinor.
1078
1079 Installing a singleton type into a uri allows developers to provide arbitrary functionality
1080 (methods and properties) to clients without requiring individual instances ot the type to be
1081 instantiated by the client.
1082
1083 A singleton type may be either a QObject or a QJSValue.
1084 This function should be used to register a singleton type provider function which returns a QObject
1085 of the given type T as a singleton type.
1086
1087 A QObject singleton type may be referenced via the type name with which it was registered, and this
1088 typename may be used as the target in a \l Connections type or otherwise used as any other type id would.
1089 One exception to this is that a QObject singleton type property may not be aliased.
1090
1091 \b{NOTE:} A QObject singleton type instance returned from a singleton type provider is owned by
1092 the QML engine unless the object has explicit QQmlEngine::CppOwnership flag set.
1093
1094 Usage:
1095 \code
1096 // First, define your QObject which provides the functionality.
1097 class SingletonTypeExample : public QObject
1098 {
1099 Q_OBJECT
1100 Q_PROPERTY (int someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged)
1101
1102 public:
1103 SingletonTypeExample(QObject *parent = nullptr)
1104 : QObject(parent), m_someProperty(0)
1105 {
1106 }
1107
1108 ~SingletonTypeExample() {}
1109
1110 Q_INVOKABLE int doSomething() { setSomeProperty(5); return m_someProperty; }
1111
1112 int someProperty() const { return m_someProperty; }
1113 void setSomeProperty(int val) { m_someProperty = val; emit somePropertyChanged(val); }
1114
1115 signals:
1116 void somePropertyChanged(int newValue);
1117
1118 private:
1119 int m_someProperty;
1120 };
1121
1122 // Second, define the singleton type provider function (callback).
1123 static QObject *example_qobject_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
1124 {
1125 Q_UNUSED(engine)
1126 Q_UNUSED(scriptEngine)
1127
1128 SingletonTypeExample *example = new SingletonTypeExample();
1129 return example;
1130 }
1131
1132 // Third, register the singleton type provider with QML by calling this function in an initialization function.
1133 qmlRegisterSingletonType<SingletonTypeExample>("Qt.example.qobjectSingleton", 1, 0, "MyApi", example_qobject_singletontype_provider);
1134 \endcode
1135
1136 Alternatively, you can use a C++11 lambda:
1137
1138 \code
1139 qmlRegisterSingletonType<SingletonTypeExample>("Qt.example.qobjectSingleton", 1, 0, "MyApi", [](QQmlEngine *engine, QJSEngine *scriptEngine) -> QObject * {
1140 Q_UNUSED(engine)
1141 Q_UNUSED(scriptEngine)
1142
1143 SingletonTypeExample *example = new SingletonTypeExample();
1144 return example;
1145 });
1146 \endcode
1147
1148 In order to use the registered singleton type in QML, you must import the singleton type.
1149 \qml
1150 import QtQuick 2.0
1151 import Qt.example.qobjectSingleton 1.0
1152 Item {
1153 id: root
1154 property int someValue: MyApi.someProperty
1155
1156 Component.onCompleted: {
1157 someValue = MyApi.doSomething()
1158 }
1159 }
1160 \endqml
1161
1162 \sa QML_SINGLETON, {Choosing the Correct Integration Method Between C++ and QML}
1163*/
1164
1165
1166/*!
1167 \fn int qmlRegisterSingletonType(const char *uri, int versionMajor, int versionMinor, const char *typeName, std::function<QObject*(QQmlEngine *, QJSEngine *)> callback)
1168 \relates QQmlEngine
1169
1170 \overload qmlRegisterSingletonType
1171 \since 5.14
1172*/
1173
1174/*!
1175 \fn int qmlRegisterSingletonType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName)
1176 \relates QQmlEngine
1177
1178 This function may be used to register a singleton type with the name \a qmlName, in the library imported from \a uri having
1179 the version number composed from \a versionMajor and \a versionMinor. The type is defined by the QML file located at \a url.
1180 The url must be an absolute URL, i.e. url.isRelative() == false.
1181
1182 In addition the type's QML file must have pragma Singleton statement among its import statements.
1183
1184 A singleton type may be referenced via the type name with which it was registered, and this typename may be used as the
1185 target in a \l Connections type or otherwise used as any other type id would. One exception to this is that a singleton
1186 type property may not be aliased (because the singleton type name does not identify an object within the same component
1187 as any other item).
1188
1189 Usage:
1190 \qml
1191 // First, define your QML singleton type which provides the functionality.
1192 pragma Singleton
1193 import QtQuick 2.0
1194 Item {
1195 property int testProp1: 125
1196 }
1197 \endqml
1198
1199 \code
1200 // Second, register the QML singleton type by calling this function in an initialization function.
1201 qmlRegisterSingletonType(QUrl("file:///absolute/path/SingletonType.qml"), "Qt.example.qobjectSingleton", 1, 0, "RegisteredSingleton");
1202 \endcode
1203
1204 In order to use the registered singleton type in QML, you must import the singleton type.
1205 \qml
1206 import QtQuick 2.0
1207 import Qt.example.qobjectSingleton 1.0
1208 Item {
1209 id: root
1210 property int someValue: RegisteredSingleton.testProp1
1211 }
1212 \endqml
1213
1214 It is also possible to have QML singleton types registered without using the qmlRegisterSingletonType function.
1215 That can be done by adding a pragma Singleton statement among the imports of the type's QML file. In addition
1216 the type must be defined in a qmldir file with a singleton keyword and the qmldir must be imported by the QML
1217 files using the singleton.
1218
1219 \sa QML_SINGLETON
1220*/
1221
1222/*!
1223 \fn int qmlRegisterSingletonInstance(const char *uri, int versionMajor, int versionMinor, const char *typeName, QObject *cppObject)
1224 \relates QQmlEngine
1225 \since 5.14
1226
1227 This function is used to register a singleton object \a cppObject, with a
1228 particular \a uri and \a typeName. Its version is a combination of \a
1229 versionMajor and \a versionMinor.
1230
1231 Installing a singleton type into a URI allows you to provide arbitrary
1232 functionality (methods and properties) to QML code without requiring
1233 individual instances of the type to be instantiated by the client.
1234
1235 Use this function to register an object of the given type T as a singleton
1236 type.
1237
1238 A QObject singleton type may be referenced via the type name with which it
1239 was registered; in turn this type name may be used as the target in a \l
1240 Connections type, or like any other type ID. However, there's one
1241 exception: a QObject singleton type property can't be aliased because the
1242 singleton type name does not identify an object within the same component
1243 as any other item.
1244
1245 \note \a cppObject must outlive the QML engine in which it is used.
1246 Moreover, \cppObject must have the same thread affinity as the engine. If
1247 you want separate singleton instances for multiple engines, you need to use
1248 \l {qmlRegisterSingletonType}. See \l{Threads and QObjects} for more
1249 information about thread safety.
1250
1251 \b{NOTE:} qmlRegisterSingleton can only be used when all types of that module are registered procedurally.
1252
1253 Usage:
1254 \code
1255 // First, define your QObject which provides the functionality.
1256 class SingletonTypeExample : public QObject
1257 {
1258 Q_OBJECT
1259 Q_PROPERTY(int someProperty READ someProperty WRITE setSomeProperty NOTIFY somePropertyChanged)
1260
1261 public:
1262 explicit SingletonTypeExample(QObject* parent = nullptr) : QObject(parent) {}
1263
1264 Q_INVOKABLE int doSomething()
1265 {
1266 setSomeProperty(5);
1267 return m_someProperty;
1268 }
1269
1270 int someProperty() const { return m_someProperty; }
1271 void setSomeProperty(int val) {
1272 if (m_someProperty != val) {
1273 m_someProperty = val;
1274 emit somePropertyChanged(val);
1275 }
1276 }
1277
1278 signals:
1279 void somePropertyChanged(int newValue);
1280
1281 private:
1282 int m_someProperty = 0;
1283 };
1284 \endcode
1285
1286 \code
1287 // Second, create an instance of the object
1288
1289 // allocate example before the engine to ensure that it outlives it
1290 QScopedPointer<SingletonTypeExample> example(new SingletonTypeExample);
1291 QQmlEngine engine;
1292
1293 // Third, register the singleton type provider with QML by calling this
1294 // function in an initialization function.
1295 qmlRegisterSingletonInstance("Qt.example.qobjectSingleton", 1, 0, "MyApi", example.get());
1296 \endcode
1297
1298
1299 In order to use the registered singleton type in QML, you must import the
1300 URI with the corresponding version.
1301 \qml
1302 import QtQuick 2.0
1303 import Qt.example.qobjectSingleton 1.0
1304 Item {
1305 id: root
1306 property int someValue: MyApi.someProperty
1307
1308 Component.onCompleted: {
1309 console.log(MyApi.doSomething())
1310 }
1311 }
1312 \endqml
1313
1314 \sa QML_SINGLETON, qmlRegisterSingletonType
1315 */
1316
1317/*!
1318 \fn int qmlRegisterType(const QUrl &url, const char *uri, int versionMajor, int versionMinor, const char *qmlName);
1319 \relates QQmlEngine
1320
1321 This function registers a type in the QML system with the name \a qmlName, in the library imported from \a uri having the
1322 version number composed from \a versionMajor and \a versionMinor. The type is defined by the QML file located at \a url. The
1323 url must be an absolute URL, i.e. url.isRelative() == false.
1324
1325 Normally QML files can be loaded as types directly from other QML files, or using a qmldir file. This function allows
1326 registration of files to types from C++ code, such as when the type mapping needs to be procedurally determined at startup.
1327
1328 Returns -1 if the registration was not successful.
1329*/
1330
1331/*!
1332 \fn bool qmlProtectModule(const char* uri, int majVersion);
1333 \relates QQmlEngine
1334
1335 This function protects a module from further modification. This can be used
1336 to prevent other plugins from injecting types into your module. It can also
1337 be a performance improvement, as it allows the engine to skip checking for
1338 the possibility of new types or plugins when this import is reached.
1339
1340 Once qmlProtectModule has been called, a QML engine will not search for a new
1341 \c qmldir file to load the module anymore. It will re-use any \c qmldir files
1342 it has loaded before, though. Therefore, types present at this point continue
1343 to work. Mind that different QML engines may load different modules. The
1344 module protection, however, is global and affects all engines. The overhead
1345 of locating \c qmldir files and loading plugins may be noticeable with slow file
1346 systems. Therefore, protecting a module once you are sure you won't need to
1347 load it anymore can be a good optimization. Mind also that the module lock
1348 not only affects plugins but also any other qmldir directives, like \c import
1349 or \c prefer, as well as any composite types or scripts declared in a \c qmldir
1350 file.
1351
1352 In addition, after this function is called, any attempt to register C++ types
1353 into this uri, major version combination will lead to a runtime error.
1354
1355 Returns true if the module with \a uri as a \l{Identified Modules}
1356 {module identifier} and \a majVersion as a major version number was found
1357 and locked, otherwise returns false. The module must contain exported types
1358 in order to be found.
1359*/
1360
1361/*!
1362 \since 5.9
1363 \fn void qmlRegisterModule(const char* uri, int versionMajor, int versionMinor);
1364 \relates QQmlEngine
1365
1366 This function registers a module in a particular \a uri with a version specified
1367 in \a versionMajor and \a versionMinor.
1368
1369 This can be used to make a certain module version available, even if no types
1370 are registered for that version. This is particularly useful for keeping the
1371 versions of related modules in sync.
1372*/
1373
1374/*!
1375 \since 5.12
1376 \fn int qmlTypeId(const char* uri, int versionMajor, int versionMinor, const char *qmlName);
1377 \relates QQmlEngine
1378
1379 Returns the QML type id of a type that was registered with the
1380 name \a qmlName in a particular \a uri and a version specified in \a
1381 versionMajor and \a versionMinor.
1382
1383 This function returns the same value as the QML type registration functions
1384 such as qmlRegisterType() and qmlRegisterSingletonType().
1385
1386 If \a qmlName, \a uri and \a versionMajor match a registered type, but the
1387 specified minor version in \a versionMinor is higher, then the id of the type
1388 with the closest minor version is returned.
1389
1390 Returns -1 if no matching type was found or one of the given parameters
1391 was invalid.
1392
1393 \sa QML_ELEMENT, QML_NAMED_ELEMENT, QML_SINGLETON, qmlRegisterType(), qmlRegisterSingletonType()
1394*/
1395
1396/*!
1397 \macro QML_VALUE_TYPE(name)
1398 \relates QQmlEngine
1399
1400 Declares the enclosing type or namespace to be available in QML, using \a name
1401 as the name. The type has to be a value type and the name has to be lower case.
1402
1403 \code
1404 class MyValueType
1405 {
1406 Q_GADGET
1407 QML_VALUE_TYPE(myValueType)
1408
1409 // ...
1410 };
1411 \endcode
1412
1413 \sa {Choosing the Correct Integration Method Between C++ and QML}, QML_NAMED_ELEMENT
1414*/
1415
1416/*!
1417 \macro QML_CONSTRUCTIBLE_VALUE
1418 \internal
1419 \relates QQmlEngine
1420
1421 Marks the surrounding value type as constructible. That is, any \l Q_INVOKABLE
1422 constructors of the type that take exactly one argument can be used when
1423 assigning a JavaScript value to a property of this type.
1424
1425 You can declare a constructible value type as follows:
1426
1427 \code
1428 class MyValueType
1429 {
1430 Q_GADGET
1431 QML_VALUE_TYPE(myValueType)
1432 QML_CONSTRUCTIBLE_VALUE
1433 Q_INVOKABLE MyValueType(double d);
1434
1435 // ...
1436 };
1437 \endcode
1438
1439 With the above type, the following QML code will produce a \c MyValueType
1440 value using the given constructor and assign it to the property.
1441
1442 \qml
1443 QtObject {
1444 property myValueType v: 5.4
1445 }
1446 \endqml
1447
1448 \sa QML_VALUE_TYPE
1449*/
1450
1451/*!
1452 \macro QML_STRUCTURED_VALUE
1453 \internal
1454 \relates QQmlEngine
1455
1456 Marks the surrounding value type as structured. Structured value types can
1457 and will preferably be constructed property-by-property from a JavaScript
1458 object. A structured value type, however is always \l QML_CONSTRUCTIBLE_VALUE,
1459 too. This means, you can still provide \l Q_INVOKABLE constructors in order to
1460 handle construction from primitive types.
1461
1462 You can declare a structured value type as follows:
1463
1464 \code
1465 class MyValueType
1466 {
1467 Q_GADGET
1468 QML_VALUE_TYPE(myValueType)
1469 QML_STRUCTURED_VALUE
1470 Q_PROPERTY(double d READ d WRITE setD)
1471 Q_PROPERTY(string e READ e WRITE setE)
1472
1473 // ...
1474 };
1475 \endcode
1476
1477 Then you can populate a property of this type as follows:
1478
1479 \qml
1480 QtObject {
1481 property myValueType v: ({d: 4.4, e: "a string"})
1482 }
1483 \endqml
1484
1485 The extra parentheses are necessary to disambiguate the JavaScript object
1486 from what might be interpreted as a JavaScript code block.
1487
1488 \sa QML_VALUE_TYPE QML_CONSTRUCTIBLE_VALUE
1489*/