Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qqmlprivate.h
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
4#ifndef QQMLPRIVATE_H
5#define QQMLPRIVATE_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQml/qtqmlglobal.h>
19#include <QtQml/qqmlparserstatus.h>
20#include <QtQml/qqmllist.h>
21#include <QtQml/qqmlpropertyvaluesource.h>
22#include <QtQml/qjsvalue.h>
23
24#include <QtCore/qglobal.h>
25#include <QtCore/qvariant.h>
26#include <QtCore/qurl.h>
27#include <QtCore/qpointer.h>
28#include <QtCore/qversionnumber.h>
29
30#include <QtCore/qmetaobject.h>
31#include <QtCore/qmetacontainer.h>
32#include <QtCore/qdebug.h>
33
34#include <functional>
35#include <type_traits>
36#include <limits>
37
39
41class QQmlContextData;
43
44namespace QQmlPrivate {
45struct CachedQmlUnit;
46template<typename A>
48}
49
50namespace QV4 {
51struct ExecutionEngine;
52class ExecutableCompilationUnit;
53namespace CompiledData {
54struct Unit;
55}
56}
57namespace QmlIR {
58struct Document;
60}
61
63
64inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
65{
66 return qHash(quintptr(func), seed);
67}
68
69template <typename TYPE>
71{
72public:
73 enum {
75 };
76};
77
78
79class QJSEngine;
80class QQmlEngine;
83
84template<class T>
86{
87 return nullptr;
88}
89
90namespace QQmlPrivate
91{
92 void Q_QML_EXPORT qdeclarativeelement_destructor(QObject *);
93 template<typename T>
94 class QQmlElement final : public T
95 {
96 public:
97 ~QQmlElement() override {
99 }
100 static void operator delete(void *ptr) {
101 // We allocate memory from this class in QQmlType::create
102 // along with some additional memory.
103 // So we override the operator delete in order to avoid the
104 // sized operator delete to be called with a different size than
105 // the size that was allocated.
106 ::operator delete (ptr);
107 }
108#ifdef Q_CC_MSVC
109 static void operator delete(void *, void *) {
110 // Deliberately empty placement delete operator.
111 // Silences MSVC warning C4291: no matching operator delete found
112 // On MinGW it causes -Wmismatched-new-delete, though.
113 }
114#endif
115 };
116
118 {
119 None,
121 Factory,
123 };
124
125 template<typename T, typename WrapperT = T, typename = std::void_t<>>
127 {
128 static constexpr bool value = false;
129 };
130
131 template<typename T, typename WrapperT>
132 struct HasSingletonFactory<T, WrapperT, std::void_t<decltype(WrapperT::create(
133 static_cast<QQmlEngine *>(nullptr),
134 static_cast<QJSEngine *>(nullptr)))>>
135 {
136 static constexpr bool value = std::is_same_v<
137 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
138 static_cast<QJSEngine *>(nullptr))), T *>;
139 };
140
141 template<typename T, typename WrapperT>
143 {
144 if constexpr (!std::is_base_of<QObject, T>::value)
146 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
148 if constexpr (std::is_default_constructible<T>::value)
150 if constexpr (HasSingletonFactory<T>::value)
152
154 }
155
156 template<typename>
158
159 template<typename Ret, typename Class>
160 struct QmlMarkerFunction<Ret (Class::*)()>
161 {
162 using ClassType = Class;
163 };
164
165 template<typename T, typename Marker>
166 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
167
168 template<typename T>
169 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
170
171 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
173 {
174 Q_UNUSED(q);
175 Q_UNUSED(j);
177 return new T;
178 else if constexpr (Mode == SingletonConstructionMode::Factory)
179 return T::create(q, j);
181 return WrapperT::create(q, j);
182 else
183 return nullptr;
184 }
185
186 template<typename T>
187 QObject *createParent(QObject *p) { return new T(p); }
188
189 using CreateIntoFunction = void (*)(void *, void *);
193
194 template<typename T, typename WrapperT = T,
195 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
197
198 template<typename T, typename WrapperT>
200 {
202 = QQmlPrivate::createInto<T>;
206 };
207
208 template<typename T, typename WrapperT>
210 {
211 static constexpr CreateIntoFunction createInto = nullptr;
213 };
214
215 template<typename T, typename WrapperT>
217 {
218 static constexpr CreateIntoFunction createInto = nullptr;
222 };
223
224 template<typename T, typename WrapperT>
226 {
227 static constexpr CreateIntoFunction createInto = nullptr;
231 };
232
233 template<typename T,
234 bool IsObject = std::is_base_of<QObject, T>::value,
237
238 template<typename T>
240 {
241 static constexpr const CreateParentFunction createParent = nullptr;
242 static const QMetaObject *staticMetaObject() { return nullptr; }
243 };
244
245 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
246 template<typename T>
247 struct ExtendedType<T, true, false>
248 {
249 static constexpr const CreateParentFunction createParent = QQmlPrivate::createParent<T>;
250 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
251 };
252
253 // If it's a Q_GADGET, we don't want the ctor.
254 template<typename T>
255 struct ExtendedType<T, false, true>
256 {
257 static constexpr const CreateParentFunction createParent = nullptr;
258 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
259 };
260
261 template<typename F, typename Result = void>
263 {
264 static constexpr const Result (*create)(const QJSValue &) = nullptr;
265 };
266
267 template<typename F>
268 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
269 {
270 static decltype(F::create(QJSValue())) create(const QJSValue &params)
271 {
272 return F::create(params);
273 }
274 };
275
276 template<typename T, typename F,
277 bool HasCtor = std::is_constructible_v<T, QJSValue>,
278 bool HasFactory = std::is_constructible_v<
280 struct ValueType;
281
282 template<typename T, typename F>
284 {
285 static constexpr const CreateValueTypeFunction create = nullptr;
286 };
287
288 template<typename T, typename F, bool HasCtor>
290 {
292 {
293 return F::create(params);
294 }
295 };
296
297 template<typename T, typename F>
299 {
301 {
302 return QVariant::fromValue(T(params));
303 }
304 };
305
306 template<class From, class To, int N>
308 {
309 static inline int cast() { return -1; }
310 };
311
312 template<class From, class To>
313 struct StaticCastSelectorClass<From, To, sizeof(int)>
314 {
315 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
316 };
317
318 template<class From, class To>
320 {
321 typedef int yes_type;
322 typedef char no_type;
323
324 static yes_type checkType(To *);
325 static no_type checkType(...);
326
327 static inline int cast()
328 {
330 }
331 };
332
333 // You can prevent subclasses from using the same attached type by specialzing this.
334 // This is reserved for internal types, though.
335 template<class T, class A>
337 {
338 using Type = A;
339 };
340
341 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
343 {
344 using Type = void;
346 static const QMetaObject *staticMetaObject() { return nullptr; }
347 static Func attachedPropertiesFunc() { return nullptr; }
348 };
349
350 // Defined inline via QML_ATTACHED
351 template<class T>
352 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
353 {
354 // Normal attached properties
355 template <typename Parent, typename Attached>
356 struct Properties
357 {
359 static const QMetaObject *staticMetaObject() { return &Attached::staticMetaObject; }
360 static Func attachedPropertiesFunc() { return Parent::qmlAttachedProperties; }
361 };
362
363 // Disabled via OverridableAttachedType
364 template<typename Parent>
365 struct Properties<Parent, void>
366 {
368 static const QMetaObject *staticMetaObject() { return nullptr; };
369 static Func attachedPropertiesFunc() { return nullptr; };
370 };
371
372 using Type = typename std::conditional<
373 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_attached)>::value,
376
378 {
379 return Properties<T, Type>::staticMetaObject();
380 }
381
383 {
384 return Properties<T, Type>::attachedPropertiesFunc();
385 }
386 };
387
388 // Separately defined via QQmlTypeInfo
389 template<class T>
390 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
391 {
392 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
394
395 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
396 static Func attachedPropertiesFunc() { return T::qmlAttachedProperties; }
397 };
398
399 // This is necessary because both the type containing a default template parameter and the type
400 // instantiating the template need to have access to the default template parameter type. In
401 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
402 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
403 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
404 // struct "fixes" that. For convenience we still want the free standing functions in addition.
405 template<class T>
407 {
409 {
411 }
412
414 {
416 }
417 };
418
419 template<typename T>
421 {
423 }
424
425 template<typename T>
427 {
429 }
430
433
435
437 enum StructVersion: int {
438 Base = 0,
442 };
443
444 bool has(StructVersion v) const { return structVersion >= int(v); }
445
447
451 // The second parameter of create is for userdata
452 void (*create)(void *, void *);
453 void *userdata;
455
456 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
458
459 const char *uri;
461 const char *elementName;
463
466
470
471 QObject *(*extensionObjectCreate)(QObject *);
473
475
478
480 // If this is extended ensure "version" is bumped!!!
481 };
482
485
489 void (*create)(void *, void *);
490 void *userdata;
491
493
494 const char *uri;
496
499
502
506
507 QObject *(*extensionObjectCreate)(QObject *);
509
510 QQmlCustomParser *(*customParserFactory)();
513
516 };
517
520
523
524 const char *iid;
525
526 const char *uri;
528 };
529
532
534 };
535
538
539 const char *uri;
541 const char *typeName;
542
544 std::function<QObject*(QQmlEngine *, QJSEngine *)> qObjectApi;
545
548
549 QObject *(*extensionObjectCreate)(QObject *);
551
553 };
554
557 const char *uri;
559
560 std::function<QObject*(QQmlEngine *, QJSEngine *)> qObjectApi;
561
564
566
567 QObject *(*extensionObjectCreate)(QObject *);
569
571 };
572
576 const char *uri;
578 const char *typeName;
579 };
580
584 const char *uri;
586 const char *typeName;
587 };
588
591 const char *uri;
593
594 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
595 // and that's automatic.
596 const char *typeName;
597
601 };
602
605 const char *uri;
607
611
613 };
614
615 struct Q_QML_EXPORT AOTCompiledContext {
616 enum: uint { InvalidStringId = (std::numeric_limits<uint>::max)() };
617
621 union {
624 };
625
626 QObject *thisObject() const;
627 QQmlEngine *qmlEngine() const;
628
629 QJSValue jsMetaType(int index) const;
630 void setInstructionPointer(int offset) const;
631 void setReturnValueUndefined() const;
632
633 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
634 bool captureLookup(uint index, QObject *object) const;
635 bool captureQmlContextPropertyLookup(uint index) const;
636 void captureTranslation() const;
637 QString translationContext() const;
638 QMetaType lookupResultMetaType(uint index) const;
639 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
640 QJSValue javaScriptGlobalProperty(uint nameIndex) const;
641
642 const QLoggingCategory *resolveLoggingCategory(QObject *wrapper, bool *ok) const;
643
644 void writeToConsole(
646 const QLoggingCategory *loggingCategory) const;
647
648 QVariant constructValueType(
649 QMetaType resultMetaType, const QMetaObject *resultMetaObject,
650 int ctorIndex, void *ctorArg) const;
651
652 // All of these lookup functions should be used as follows:
653 //
654 // while (!fooBarLookup(...)) {
655 // setInstructionPointer(...);
656 // initFooBarLookup(...);
657 // if (engine->hasException()) {
658 // ...
659 // break;
660 // }
661 // }
662 //
663 // The bool-returning *Lookup functions exclusively run the happy path and return false if
664 // that fails in any way. The failure may either be in the lookup structs not being
665 // initialized or an exception being thrown.
666 // The init*Lookup functions initialize the lookup structs and amend any exceptions
667 // previously thrown with line numbers. They might also throw their own exceptions. If an
668 // exception is present after the initialization there is no way to carry out the lookup and
669 // the exception should be propagated. If not, the original lookup can be tried again.
670
671 bool callQmlContextPropertyLookup(
672 uint index, void **args, const QMetaType *types, int argc) const;
673 void initCallQmlContextPropertyLookup(uint index) const;
674
675 bool loadContextIdLookup(uint index, void *target) const;
676 void initLoadContextIdLookup(uint index) const;
677
678 bool callObjectPropertyLookup(uint index, QObject *object,
679 void **args, const QMetaType *types, int argc) const;
680 void initCallObjectPropertyLookup(uint index) const;
681
682 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
683 void initCallGlobalLookup(uint index) const;
684
685 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
686 void initLoadGlobalLookup(uint index) const;
687
688 bool loadScopeObjectPropertyLookup(uint index, void *target) const;
689 void initLoadScopeObjectPropertyLookup(uint index, QMetaType type) const;
690
691 bool loadSingletonLookup(uint index, void *target) const;
692 void initLoadSingletonLookup(uint index, uint importNamespace) const;
693
694 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
695 void initLoadAttachedLookup(uint index, uint importNamespace, QObject *object) const;
696
697 bool loadTypeLookup(uint index, void *target) const;
698 void initLoadTypeLookup(uint index, uint importNamespace) const;
699
700 bool getObjectLookup(uint index, QObject *object, void *target) const;
701 void initGetObjectLookup(uint index, QObject *object, QMetaType type) const;
702
703 bool getValueLookup(uint index, void *value, void *target) const;
704 void initGetValueLookup(uint index, const QMetaObject *metaObject, QMetaType type) const;
705
706 bool getEnumLookup(uint index, void *target) const;
707 void initGetEnumLookup(uint index, const QMetaObject *metaObject,
708 const char *enumerator, const char *enumValue) const;
709
710 bool setObjectLookup(uint index, QObject *object, void *value) const;
711 void initSetObjectLookup(uint index, QObject *object, QMetaType type) const;
712
713 bool setValueLookup(uint index, void *target, void *value) const;
714 void initSetValueLookup(uint index, const QMetaObject *metaObject, QMetaType type) const;
715 };
716
721 void (*functionPtr)(const AOTCompiledContext *context, void *resultPtr, void **arguments);
722 };
723
724#if QT_DEPRECATED_SINCE(6, 6)
725 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
726 typedef AOTCompiledFunction TypedFunction;
727#endif
728
732 void *unused2;
733 };
734
735 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
739 };
740
753 };
754
755 int Q_QML_EXPORT qmlregister(RegistrationType, void *);
756 void Q_QML_EXPORT qmlunregister(RegistrationType, quintptr);
757
758#if QT_DEPRECATED_SINCE(6, 3)
759 struct Q_QML_EXPORT SingletonFunctor
760 {
761 QT_DEPRECATED QObject *operator()(QQmlEngine *, QJSEngine *);
762 QPointer<QObject> m_object;
763 bool alreadyCalled = false;
764 };
765#endif
766
767 struct Q_QML_EXPORT SingletonInstanceFunctor
768 {
769 QObject *operator()(QQmlEngine *, QJSEngine *);
770
772
773 // Not a QPointer, so that you cannot assign it to a different
774 // engine when the first one is deleted.
775 // That would mess up the QML contexts.
776 QQmlEngine *m_engine = nullptr;
777 };
778
779 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
780 {
781 if (!metaObject || !key)
782 return -1;
783
784 const int offset = metaObject->classInfoOffset();
785 const int start = (startOffset == -1)
786 ? (metaObject->classInfoCount() + offset - 1)
787 : startOffset;
788 for (int i = start; i >= offset; --i)
789 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
790 return i;
791 }
792 return -1;
793 }
794
795 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
796 {
797 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
798 }
799
801 QTypeRevision defaultValue = QTypeRevision())
802 {
804 return (index == -1) ? defaultValue
806 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
807 }
808
809 Q_QML_EXPORT QList<QTypeRevision> revisionClassInfos(const QMetaObject *metaObject, const char *key);
810
811 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
812 bool defaultValue = false)
813 {
815 if (index == -1)
816 return defaultValue;
817 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
818 }
819
820 inline const char *classElementName(const QMetaObject *metaObject)
821 {
822 const char *elementName = classInfo(metaObject, "QML.Element");
823 if (qstrcmp(elementName, "auto") == 0) {
824 const char *strippedClassName = metaObject->className();
825 for (const char *c = strippedClassName; *c != '\0'; c++) {
826 if (*c == ':')
827 strippedClassName = c + 1;
828 }
829
830 return strippedClassName;
831 }
832 if (qstrcmp(elementName, "anonymous") == 0)
833 return nullptr;
834
835 if (!elementName) {
836 qWarning().nospace() << "Missing QML.Element class info \"" << elementName << "\""
837 << " for " << metaObject->className();
838 }
839
840 return elementName;
841 }
842
843 template<class T, class = std::void_t<>>
845 {
846 using Type = void;
847 };
848
849 template<class T>
850 struct QmlExtended<T, std::void_t<typename T::QmlExtendedType>>
851 {
852 using Type = typename std::conditional<
853 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_extended)>::value,
854 typename T::QmlExtendedType, void>::type;
855 };
856
857 template<class T, class = std::void_t<>>
859 {
860 static constexpr const QMetaObject *metaObject() { return nullptr; }
861 };
862
863 template<class T>
864 struct QmlExtendedNamespace<T, std::void_t<decltype(T::qmlExtendedNamespace())>>
865 {
866 static constexpr const QMetaObject *metaObject()
867 {
868 if constexpr (QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_extendedNamespace)>::value)
869 return T::qmlExtendedNamespace();
870 else
871 return nullptr;
872 }
873 };
874
875 template<class T, class = std::void_t<>>
877 {
878 using Type = T;
879 };
880
881 template<class T>
882 struct QmlResolved<T, std::void_t<typename T::QmlForeignType>>
883 {
884 using Type = typename std::conditional<
885 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_foreign)>::value,
886 typename T::QmlForeignType, T>::type;
887 };
888
889 template<class T, class = std::void_t<>>
891 {
892 static constexpr bool Value = false;
893 };
894
895 template<class T>
896 struct QmlUncreatable<T, std::void_t<typename T::QmlIsUncreatable>>
897 {
898 static constexpr bool Value =
899 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_uncreatable)>::value
900 && bool(T::QmlIsUncreatable::yes);
901 };
902
903 template<class T, class = std::void_t<>>
905 {
906 static constexpr bool Value = false;
907 };
908
909 template<class T>
910 struct QmlAnonymous<T, std::void_t<typename T::QmlIsAnonymous>>
911 {
912 static constexpr bool Value =
913 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_anonymous)>::value
914 && bool(T::QmlIsAnonymous::yes);
915 };
916
917
918 template<class T, class = std::void_t<>>
920 {
921 static constexpr bool Value = false;
922 };
923
924 template<class T>
925 struct QmlSingleton<T, std::void_t<typename T::QmlIsSingleton>>
926 {
927 static constexpr bool Value =
928 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_singleton)>::value
929 && bool(T::QmlIsSingleton::yes);
930 };
931
932 template<class T, class = std::void_t<>>
934 {
935 static constexpr bool Value = false;
936 };
937
938 template<class T>
939 struct QmlSequence<T, std::void_t<typename T::QmlIsSequence>>
940 {
941 Q_STATIC_ASSERT((std::is_same_v<typename T::QmlSequenceValueType,
943 static constexpr bool Value = bool(T::QmlIsSequence::yes);
944 };
945
946 template<class T, class = std::void_t<>>
948 {
949 static constexpr bool Value = false;
950 };
951
952 template<class T>
953 struct QmlInterface<T, std::void_t<typename T::QmlIsInterface>>
954 {
955 static constexpr bool Value = bool(T::QmlIsInterface::yes);
956 };
957
958 template<class T, typename = std::void_t<>>
960 {
961 static const QMetaObject *staticMetaObject() { return nullptr; }
962 };
963
964 template<class T>
965 struct StaticMetaObject<T, std::void_t<decltype(T::staticMetaObject)>>
966 {
967 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
968 };
969
970 template<class T>
972 {
973 static constexpr bool hasAcceptableCtors()
974 {
975 if constexpr (!std::is_default_constructible_v<T>)
976 return false;
977 else if constexpr (std::is_base_of_v<QObject, T>)
978 return true;
979 else
980 return std::is_copy_constructible_v<T>;
981 }
982
984 {
985 if constexpr (std::is_base_of_v<QObject, T>)
986 return QMetaType::fromType<T*>();
987 else
988 return QMetaType::fromType<T>();
989 }
990
992 {
993 if constexpr (std::is_base_of_v<QObject, T>)
995 else
996 return QMetaType::fromType<QList<T>>();
997 }
998
1000 {
1001 if constexpr (std::is_base_of_v<QObject, T>)
1002 return QMetaSequence();
1003 else
1004 return QMetaSequence::fromContainer<QList<T>>();
1005 }
1006 };
1007
1008 template<typename T, typename E, typename WrapperT = T>
1009 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1010 const QMetaObject *classInfoMetaObject,
1011 QVector<int> *qmlTypeIds, const QMetaObject *extension)
1012 {
1013 static_assert(std::is_base_of_v<QObject, T>);
1015 0,
1016
1017 uri,
1018 QTypeRevision::fromMajorVersion(versionMajor),
1019
1021
1023 classInfoMetaObject,
1024
1026
1029
1030 qmlTypeIds
1031 };
1032
1034 }
1035
1036 template<typename T, typename E>
1037 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1038 const QMetaObject *classInfoMetaObject,
1039 QVector<int> *qmlTypeIds, const QMetaObject *extension,
1040 bool forceAnonymous = false)
1041 {
1043 3,
1046 int(sizeof(T)),
1048 nullptr,
1050
1051 uri,
1052 QTypeRevision::fromMajorVersion(versionMajor),
1053
1055 classInfoMetaObject,
1056
1057 attachedPropertiesFunc<T>(),
1058 attachedPropertiesMetaObject<T>(),
1059
1063
1066
1067 &qmlCreateCustomParser<T>,
1068 qmlTypeIds,
1070
1071 forceAnonymous,
1073 };
1074
1075 // Initialize the extension so that we can find it by name or ID.
1076 qMetaTypeId<E>();
1077
1079 }
1080
1081 template<typename T>
1082 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1083 const QMetaObject *classInfoMetaObject,
1084 QVector<int> *qmlTypeIds)
1085 {
1087 0,
1088 uri,
1089 QTypeRevision::fromMajorVersion(versionMajor),
1090 classInfoMetaObject,
1091 QMetaType::fromType<T>(),
1092 QMetaSequence::fromContainer<T>(),
1093 qmlTypeIds
1094 };
1095
1097 }
1098
1099 template<>
1101 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1102 QVector<int> *qmlTypeIds, const QMetaObject *, bool);
1103
1105 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1106 {
1107 return {
1108 /*.revision=*/ 0,
1109 /*.alignment=*/ 0,
1110 /*.size=*/ 0,
1111 /*.flags=*/ 0,
1112 /*.typeId=*/ {},
1113 /*.metaObject=*/ metaObjectFunction,
1114 /*.name=*/ name,
1115 /*.defaultCtr=*/ nullptr,
1116 /*.copyCtr=*/ nullptr,
1117 /*.moveCtr=*/ nullptr,
1118 /*.dtor=*/ nullptr,
1119 /*.equals*/ nullptr,
1120 /*.lessThan*/ nullptr,
1121 /*.debugStream=*/ nullptr,
1122 /*.dataStreamOut=*/ nullptr,
1123 /*.dataStreamIn=*/ nullptr,
1124 /*.legacyRegisterOp=*/ nullptr
1125 };
1126 }
1127
1128 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1129
1134 };
1135
1136 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1137
1138} // namespace QQmlPrivate
1139
1141
1142#endif // QQMLPRIVATE_H
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
The QJSValue class acts as a container for Qt/JavaScript data types.
Definition qjsvalue.h:31
int toInt(bool *ok=nullptr, int base=10) const
Definition qlist.h:74
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:320
static constexpr QMetaType fromType()
Definition qmetatype.h:2612
\inmodule QtCore
Definition qobject.h:90
\inmodule QtCore
Definition qpointer.h:18
The QQmlCustomParser class allows you to add new arbitrary types to QML.
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
The QQmlListProperty class allows applications to expose list-like properties of QObject-derived clas...
Definition qqmllist.h:24
The QQmlPropertyValueInterceptor class is inherited by property interceptors such as Behavior.
@ hasAttachedProperties
Definition qqmlprivate.h:74
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:127
\inmodule QtCore
static constexpr QTypeRevision fromEncodedVersion(Integer value)
Produces a QTypeRevision from the given value.
static constexpr QTypeRevision fromMajorVersion(Major majorVersion)
Produces a QTypeRevision from the given majorVersion with an invalid minor version.
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:64
static auto fromValue(T &&value) noexcept(std::is_nothrow_copy_constructible_v< T > &&Private::CanUseInternalSpace< T >) -> std::enable_if_t< std::conjunction_v< std::is_copy_constructible< T >, std::is_destructible< T > >, QVariant >
Definition qvariant.h:531
const QMetaObject *(*)(const QMetaTypeInterface *) MetaObjectFn
Definition qmetatype.h:262
void extension()
[6]
Definition dialogs.cpp:230
QList< QVariant > arguments
void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds, const QMetaObject *extension, bool forceAnonymous=false)
QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key, QTypeRevision defaultValue=QTypeRevision())
void Q_QML_EXPORT qmlunregister(RegistrationType, quintptr)
Definition qqml.cpp:715
void(*)(void *, void *) CreateIntoFunction
QObject * createParent(QObject *p)
QObject *(*)(QQmlEngine *, QJSEngine *) CreateSingletonFunction
constexpr QtPrivate::QMetaTypeInterface metaTypeForNamespace(const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
QObject * createSingletonInstance(QQmlEngine *q, QJSEngine *j)
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset=-1)
void createInto(void *memory, void *)
void Q_QML_EXPORT qdeclarativeelement_destructor(QObject *)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:47
void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds, const QMetaObject *extension)
Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type)
Definition qqml.cpp:149
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds)
QVariant(*)(const QJSValue &) CreateValueTypeFunction
Q_QML_EXPORT QList< QTypeRevision > revisionClassInfos(const QMetaObject *metaObject, const char *key)
Definition qqml.cpp:747
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
Q_QML_EXPORT QObject * qmlExtendedObject(QObject *, int)
Definition qqml.cpp:130
constexpr SingletonConstructionMode singletonConstructionMode()
const CachedQmlUnit *(* QmlUnitCacheLookupFunction)(const QUrl &url)
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
std::is_same< T, typename QmlMarkerFunction< Marker >::ClassType > QmlTypeHasMarker
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
int Q_QML_EXPORT qmlregister(RegistrationType, void *)
Definition qqml.cpp:483
QObject *(*)(QObject *) CreateParentFunction
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
void qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds, const QMetaObject *extension, bool)
Definition qqml.cpp:769
const char * classElementName(const QMetaObject *metaObject)
Combined button and popup list for selecting options.
\qmltype Particle \inqmlmodule QtQuick.Particles
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:59
static void * context
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
QtMsgType
Definition qlogging.h:29
#define qWarning
Definition qlogging.h:162
static ControlElement< T > * ptr(QWidget *widget)
n varying highp vec2 A
GLsizei const GLfloat * v
[13]
GLuint64 key
GLuint index
[2]
GLsizei GLenum GLenum * types
GLuint object
[3]
GLenum type
GLenum target
GLuint GLsizei const GLchar * message
GLuint start
GLenum GLuint GLintptr offset
GLuint name
GLsizei GLenum GLsizei GLsizei GLuint memory
void ** params
GLenum func
Definition qopenglext.h:663
const GLubyte * c
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:76
static ReturnedValue writeToConsole(const FunctionObject *b, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack=false)
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:85
size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed=0)
Definition qqmlprivate.h:64
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:62
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
#define QT_DEPRECATED_VERSION_X(major, minor, text)
#define QT_DEPRECATED
#define Q_UNUSED(x)
size_t quintptr
Definition qtypes.h:72
unsigned int uint
Definition qtypes.h:29
ptrdiff_t qintptr
Definition qtypes.h:71
QUrl url("example.com")
[constructor-url-reference]
obj metaObject() -> className()
view create()
QJSValueList args
\inmodule QtCore
QV4::ExecutableCompilationUnit * compilationUnit
void(* functionPtr)(const AOTCompiledContext *context, void *resultPtr, void **arguments)
QList< QMetaType > argumentTypes
const AOTCompiledFunction * aotCompiledFunctions
const QV4::CompiledData::Unit * qmlData
static const QMetaObject * staticMetaObject()
static const QMetaObject * staticMetaObject()
static const QMetaObject * staticMetaObject()
static constexpr bool Value
static QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
QQmlAttachedPropertiesFunc< QObject > Func
static Func attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static constexpr const QMetaObject * metaObject()
static constexpr bool Value
static QMetaSequence sequence()
static QMetaType list()
static constexpr bool hasAcceptableCtors()
static QMetaType self()
Q_STATIC_ASSERT((std::is_same_v< typename T::QmlSequenceValueType, typename QmlResolved< T >::Type::value_type >))
static constexpr bool Value
static constexpr bool Value
static constexpr bool Value
QmlUnitCacheLookupFunction lookupCachedQmlUnit
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
std::function< QObject *(QQmlEngine *, QJSEngine *)> qObjectApi
std::function< QJSValue(QQmlEngine *, QJSEngine *)> scriptApi
const QMetaObject * extensionMetaObject
const QMetaObject * instanceMetaObject
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
const QMetaObject * classInfoMetaObject
const QMetaObject * attachedPropertiesMetaObject
QQmlCustomParser * customParser
void(* create)(void *, void *)
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunction
QVariant(* createValueType)(const QJSValue &)
const QMetaObject * extensionMetaObject
const QMetaObject * metaObject
const QMetaObject * attachedPropertiesMetaObject
bool has(StructVersion v) const
ValueTypeCreationMethod creationMethod
static no_type checkType(...)
static yes_type checkType(To *)
static const QMetaObject * staticMetaObject()
static decltype(F::create(QJSValue())) create(const QJSValue &params)
static constexpr const Result(* create)(const QJSValue &)
static QVariant create(const QJSValue &params)
static QVariant create(const QJSValue &params)
Definition moc.h:24
void wrapper()
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent