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
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/qjsprimitivevalue.h>
19#include <QtQml/qjsvalue.h>
20#include <QtQml/qqmllist.h>
21#include <QtQml/qqmlparserstatus.h>
22#include <QtQml/qqmlpropertyvaluesource.h>
23#include <QtQml/qtqmlglobal.h>
24
25#include <QtCore/qdatetime.h>
26#include <QtCore/qdebug.h>
27#include <QtCore/qglobal.h>
28#include <QtCore/qmetacontainer.h>
29#include <QtCore/qmetaobject.h>
30#include <QtCore/qpointer.h>
31#include <QtCore/qurl.h>
32#include <QtCore/qvariant.h>
33#include <QtCore/qversionnumber.h>
34
35#include <functional>
36#include <limits>
37#include <type_traits>
38
39QT_BEGIN_NAMESPACE
40
41class QQmlPropertyValueInterceptor;
42class QQmlContextData;
43class QQmlFinalizerHook;
44
45namespace QQmlPrivate {
46struct CachedQmlUnit;
47template<typename A>
48using QQmlAttachedPropertiesFunc = A *(*)(QObject *);
49}
50
51namespace QV4 {
52struct ExecutionEngine;
53struct MarkStack;
54class ExecutableCompilationUnit;
55namespace CompiledData {
56struct Unit;
57}
58}
59namespace QmlIR {
60struct Document;
61typedef void (*IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *);
62}
63
64using QQmlAttachedPropertiesFunc = QQmlPrivate::QQmlAttachedPropertiesFunc<QObject>;
65
66inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
67{
68 return qHash(quintptr(func), seed);
69}
70
71template <typename TYPE>
73{
74public:
75 enum {
77 };
78};
79
80
81class QJSEngine;
82class QQmlEngine;
83class QQmlCustomParser;
85
86class QQmlV4Function;
88using QQmlV4ExecutionEnginePtr = QV4::ExecutionEngine *;
89
90template<class T>
91QQmlCustomParser *qmlCreateCustomParser()
92{
93 return nullptr;
94}
95
96namespace QQmlPrivate
97{
99 template<typename T>
100 class QQmlElement final : public T
101 {
102 public:
103 // Not defaulted so that it can be specialized
105
106 ~QQmlElement() override {
107 QQmlPrivate::qdeclarativeelement_destructor(this);
108 }
109 static void operator delete(void *ptr) {
110 // We allocate memory from this class in QQmlType::create
111 // along with some additional memory.
112 // So we override the operator delete in order to avoid the
113 // sized operator delete to be called with a different size than
114 // the size that was allocated.
115 ::operator delete (ptr);
116 }
117#ifdef Q_CC_MSVC
118 static void operator delete(void *, void *) {
119 // Deliberately empty placement delete operator.
120 // Silences MSVC warning C4291: no matching operator delete found
121 // On MinGW it causes -Wmismatched-new-delete, though.
122 }
123#endif
124 };
125
133
134 template<typename T, typename WrapperT = T, typename = std::void_t<>>
136 {
137 static constexpr bool value = false;
138 };
139
140 template<typename T, typename WrapperT>
142 static_cast<QQmlEngine *>(nullptr),
143 static_cast<QJSEngine *>(nullptr)))>>
144 {
145 static constexpr bool value = std::is_same_v<
146 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
147 static_cast<QJSEngine *>(nullptr))), T *>;
148 };
149
150 template<typename T, typename WrapperT>
152 {
153 if constexpr (!std::is_base_of<QObject, T>::value)
155 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
157 if constexpr (std::is_default_constructible<T>::value)
159 if constexpr (HasSingletonFactory<T>::value)
161
163 }
164
165 template<typename>
167
168 template<typename Ret, typename Class>
169 struct QmlMarkerFunction<Ret (Class::*)()>
170 {
171 using ClassType = Class;
172 };
173
174 template<typename T, typename Marker>
175 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
176
177 template<typename T>
178 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
179
180 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
182 {
183 Q_UNUSED(q);
184 Q_UNUSED(j);
185 if constexpr (Mode == SingletonConstructionMode::Constructor)
186 return new T;
187 else if constexpr (Mode == SingletonConstructionMode::Factory)
188 return T::create(q, j);
189 else if constexpr (Mode == SingletonConstructionMode::FactoryWrapper)
190 return WrapperT::create(q, j);
191 else
192 return nullptr;
193 }
194
195 template<typename T>
196 QObject *createParent(QObject *p) { return new T(p); }
197
198 using CreateIntoFunction = void (*)(void *, void *);
202
203 template<typename T, typename WrapperT = T,
204 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
206
207 template<typename T, typename WrapperT>
209 {
211 = QQmlPrivate::createInto<T>;
213 = QQmlPrivate::createSingletonInstance<
215 };
216
217 template<typename T, typename WrapperT>
219 {
220 static constexpr CreateIntoFunction createInto = nullptr;
222 };
223
224 template<typename T, typename WrapperT>
226 {
227 static constexpr CreateIntoFunction createInto = nullptr;
229 = QQmlPrivate::createSingletonInstance<
231 };
232
233 template<typename T, typename WrapperT>
235 {
236 static constexpr CreateIntoFunction createInto = nullptr;
238 = QQmlPrivate::createSingletonInstance<
240 };
241
242 template<typename T,
246
247 template<typename T>
248 struct ExtendedType<T, false, false>
249 {
250 static constexpr const CreateParentFunction createParent = nullptr;
251 static const QMetaObject *staticMetaObject() { return nullptr; }
252 };
253
254 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
255 template<typename T>
256 struct ExtendedType<T, true, false>
257 {
259 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
260 };
261
262 // If it's a Q_GADGET, we don't want the ctor.
263 template<typename T>
264 struct ExtendedType<T, false, true>
265 {
266 static constexpr const CreateParentFunction createParent = nullptr;
267 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
268 };
269
270 template<typename F, typename Result = void>
272 {
273 static constexpr const Result (*create)(const QJSValue &) = nullptr;
274 };
275
276 template<typename F>
277 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
278 {
279 static decltype(F::create(QJSValue())) create(const QJSValue &params)
280 {
281 return F::create(params);
282 }
283 };
284
285 template<typename T, typename F,
286 bool HasCtor = std::is_constructible_v<T, QJSValue>,
287 bool HasFactory = std::is_constructible_v<
288 QVariant, decltype(ValueTypeFactory<F>::create(QJSValue()))>>
289 struct ValueType;
290
291 template<typename T, typename F>
292 struct ValueType<T, F, false, false>
293 {
294 static constexpr const CreateValueTypeFunction create = nullptr;
295 };
296
297 template<typename T, typename F, bool HasCtor>
298 struct ValueType<T, F, HasCtor, true>
299 {
300 static QVariant create(const QJSValue &params)
301 {
302 return F::create(params);
303 }
304 };
305
306 template<typename T, typename F>
307 struct ValueType<T, F, true, false>
308 {
309 static QVariant create(const QJSValue &params)
310 {
311 return QVariant::fromValue(T(params));
312 }
313 };
314
315 template<class From, class To, int N>
317 {
318 static inline int cast() { return -1; }
319 };
320
321 template<class From, class To>
322 struct StaticCastSelectorClass<From, To, sizeof(int)>
323 {
324 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
325 };
326
327 template<class From, class To>
329 {
330 typedef int yes_type;
331 typedef char no_type;
332
333 static yes_type checkType(To *);
334 static no_type checkType(...);
335
336 static inline int cast()
337 {
338 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
339 }
340 };
341
342 // You can prevent subclasses from using the same attached type by specialzing this.
343 // This is reserved for internal types, though.
344 template<class T, class A>
346 {
347 using Type = A;
348 };
349
350 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
352 {
353 using Type = void;
355 static const QMetaObject *staticMetaObject() { return nullptr; }
356 static Func attachedPropertiesFunc() { return nullptr; }
357 };
358
359 // Defined inline via QML_ATTACHED
360 template<class T>
361 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
362 {
363 // Normal attached properties
364 template <typename Parent, typename Attached>
371
372 // Disabled via OverridableAttachedType
373 template<typename Parent>
374 struct Properties<Parent, void>
375 {
377 static const QMetaObject *staticMetaObject() { return nullptr; }
378 static Func attachedPropertiesFunc() { return nullptr; }
379 };
380
381 using Type = typename std::conditional<
383 typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type, void>::type;
384 using Func = typename Properties<T, Type>::Func;
385
387 {
388 return Properties<T, Type>::staticMetaObject();
389 }
390
392 {
394 }
395 };
396
397 // Separately defined via QQmlTypeInfo
398 template<class T>
399 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
400 {
401 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
403
404 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
406 };
407
408 // This is necessary because both the type containing a default template parameter and the type
409 // instantiating the template need to have access to the default template parameter type. In
410 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
411 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
412 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
413 // struct "fixes" that. For convenience we still want the free standing functions in addition.
414 template<class T>
416 {
418 {
419 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
420 }
421
423 {
424 return QmlAttached<T>::staticMetaObject();
425 }
426 };
427
428 template<typename T>
430 {
431 return QmlAttachedAccessor<T>::attachedPropertiesFunc();
432 }
433
434 template<typename T>
436 {
437 return QmlAttachedAccessor<T>::staticMetaObject();
438 }
439
441 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
442
444
452
453 bool has(StructVersion v) const { return structVersion >= int(v); }
454
456
460 // The second parameter of create is for userdata
461 void (*create)(void *, void *);
462 void *userdata;
464
465 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
466 QVariant (*createValueType)(const QJSValue &);
467
468 const char *uri;
470 const char *elementName;
472
475
479
482
483 QQmlCustomParser *customParser;
484
487
489 // If this is extended ensure "version" is bumped!!!
490 };
491
526
538
541
542 AutoParentFunction function;
543 };
544
563
581
589
597
600 const char *uri;
602
603 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
604 // and that's automatic.
605 const char *typeName;
606
610 };
611
623
625 {
626 virtual ~AOTTrackedLocalsStorage() = default;
627 virtual void markObjects(QV4::MarkStack *markStack) const = 0;
628 };
629
630 struct Q_QML_EXPORT AOTCompiledContext {
632
636 union {
639 };
640
641 QObject *thisObject() const;
642 QQmlEngine *qmlEngine() const;
643
644 QJSValue jsMetaType(int index) const;
645 void setInstructionPointer(int offset) const;
646 void setLocals(const AOTTrackedLocalsStorage *locals) const;
647 void setReturnValueUndefined() const;
648
649 static void mark(QObject *object, QV4::MarkStack *markStack);
650 static void mark(const QVariant &variant, QV4::MarkStack *markStack);
651 template<typename T>
652 static void mark(T, QV4::MarkStack *) {}
653
654 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
655 bool captureLookup(uint index, QObject *object) const;
657 void captureTranslation() const;
660 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
662
664
665 void writeToConsole(
667 const QLoggingCategory *loggingCategory) const;
668
671 int ctorIndex, void **args) const;
672#if QT_QML_REMOVED_SINCE(6, 9)
675 int ctorIndex, void *ctorArg) const;
676#endif
677
678 // Those are explicit arguments to the Date() ctor, not implicit coercions.
687
689 double year, double month, double day = 1,
690 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
691
692 // All of these lookup functions should be used as follows:
693 //
694 // while (!fooBarLookup(...)) {
695 // setInstructionPointer(...);
696 // initFooBarLookup(...);
697 // if (engine->hasException()) {
698 // ...
699 // break;
700 // }
701 // }
702 //
703 // The bool-returning *Lookup functions exclusively run the happy path and return false if
704 // that fails in any way. The failure may either be in the lookup structs not being
705 // initialized or an exception being thrown.
706 // The init*Lookup functions initialize the lookup structs and amend any exceptions
707 // previously thrown with line numbers. They might also throw their own exceptions. If an
708 // exception is present after the initialization there is no way to carry out the lookup and
709 // the exception should be propagated. If not, the original lookup can be tried again.
710
711 bool callQmlContextPropertyLookup(uint index, void **args, int argc) const;
713
714#if QT_QML_REMOVED_SINCE(6, 9)
716 uint index, void **args, const QMetaType *types, int argc) const;
718#endif
719
720 bool loadContextIdLookup(uint index, void *target) const;
722
723 bool callObjectPropertyLookup(uint index, QObject *object, void **args, int argc) const;
727
728#if QT_QML_REMOVED_SINCE(6, 9)
730 uint index, QObject *object, void **args, const QMetaType *types, int argc) const;
732
733 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
734 void initCallGlobalLookup(uint index) const;
735
736 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
737 void initLoadGlobalLookup(uint index) const;
738#endif
739
740 bool loadGlobalLookup(uint index, void *target) const;
742
746#if QT_QML_REMOVED_SINCE(6, 9)
748#endif
749
750 bool loadSingletonLookup(uint index, void *target) const;
752
753 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
755
756 bool loadTypeLookup(uint index, void *target) const;
758
759 bool getObjectLookup(uint index, QObject *object, void *target) const;
763#if QT_QML_REMOVED_SINCE(6, 9)
765#endif
766
767 bool getValueLookup(uint index, void *value, void *target) const;
768 bool writeBackValueLookup(uint index, void *value, void *source) const;
770#if QT_QML_REMOVED_SINCE(6, 9)
772#endif
773
774 bool getEnumLookup(uint index, void *target) const;
775#if QT_QML_REMOVED_SINCE(6, 6)
776 bool getEnumLookup(uint index, int *target) const;
777#endif
779 const char *enumerator, const char *enumValue) const;
780
781 bool setObjectLookup(uint index, QObject *object, void *value) const;
784#if QT_QML_REMOVED_SINCE(6, 9)
786#endif
787
788 bool setValueLookup(uint index, void *target, void *value) const;
791#if QT_QML_REMOVED_SINCE(6, 9)
793#endif
794
795 bool callValueLookup(uint index, void *target, void **args, int argc) const;
798
805
807 {
808 // This does not cover everything you can possibly wrap into a QVariant.
809 // However, since we only _promise_ to handle single objects, this is OK.
811 return;
812
813 if (QObject *object = *static_cast<QObject *const *>(variant.constData()))
815 }
816
817 template<typename Value>
819 };
820
824 void (*signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes);
825 void (*functionPtr)(const AOTCompiledContext *context, void **argv);
826 };
827
828#if QT_DEPRECATED_SINCE(6, 6)
829 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
831#endif
832
838
839 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
842 QmlUnitCacheLookupFunction lookupCachedQmlUnit;
843 };
844
858
861
862#if QT_DEPRECATED_SINCE(6, 3)
864 {
867 bool alreadyCalled = false;
868 };
869#endif
870
871 struct Q_QML_EXPORT SingletonInstanceFunctor
872 {
874
876
877 // Not a QPointer, so that you cannot assign it to a different
878 // engine when the first one is deleted.
879 // That would mess up the QML contexts.
881 };
882
883 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
884 {
885 if (!metaObject || !key)
886 return -1;
887
888 const int offset = metaObject->classInfoOffset();
889 const int start = (startOffset == -1)
890 ? (metaObject->classInfoCount() + offset - 1)
891 : startOffset;
892 for (int i = start; i >= offset; --i)
893 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
894 return i;
895 }
896 return -1;
897 }
898
899 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
900 {
901 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
902 }
903
904 inline QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key,
905 QTypeRevision defaultValue = QTypeRevision())
906 {
907 const int index = indexOfOwnClassInfo(metaObject, key);
908 return (index == -1) ? defaultValue
909 : QTypeRevision::fromEncodedVersion(
910 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
911 }
912
914
915 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
916 bool defaultValue = false)
917 {
918 const int index = indexOfOwnClassInfo(metaObject, key);
919 if (index == -1)
920 return defaultValue;
921 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
922 }
923
924 template<class T, class = std::void_t<>>
926 {
927 using Type = void;
928 };
929
930 template<class T>
932 {
933 using Type = typename std::conditional<
935 typename T::QmlExtendedType, void>::type;
936 };
937
938 template<class T, class = std::void_t<>>
940 {
941 static constexpr const QMetaObject *metaObject() { return nullptr; }
942 };
943
944 template<class T>
946 {
947 static constexpr const QMetaObject *metaObject()
948 {
949 if constexpr (QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_extendedNamespace)>::value)
950 return T::qmlExtendedNamespace();
951 else
952 return nullptr;
953 }
954 };
955
956 template<class T, class = std::void_t<>>
958 {
959 using Type = T;
960 };
961
962 template<class T>
963 struct QmlResolved<T, std::void_t<typename T::QmlForeignType>>
964 {
965 using Type = typename std::conditional<
967 typename T::QmlForeignType, T>::type;
968 };
969
970 template<class T, class = std::void_t<>>
972 {
973 static constexpr bool Value = false;
974 };
975
976 template<class T>
978 {
979 static constexpr bool Value =
981 && bool(T::QmlIsUncreatable::yes);
982 };
983
984 template<class T, class = std::void_t<>>
986 {
987 static constexpr bool Value = false;
988 };
989
990 template<class T>
992 {
993 static constexpr bool Value =
995 && bool(T::QmlIsAnonymous::yes);
996 };
997
998
999 template<class T, class = std::void_t<>>
1001 {
1002 static constexpr bool Value = false;
1003 };
1004
1005 template<class T>
1007 {
1008 static constexpr bool Value =
1010 && bool(T::QmlIsSingleton::yes);
1011 };
1012
1013 template<class T, class = std::void_t<>>
1015 {
1016 static constexpr bool Value = false;
1017 };
1018
1019 template<class T>
1020 struct QmlSequence<T, std::void_t<typename T::QmlIsSequence>>
1021 {
1023 typename QmlResolved<T>::Type::value_type>));
1024 static constexpr bool Value = bool(T::QmlIsSequence::yes);
1025 };
1026
1027 template<class T, class = std::void_t<>>
1029 {
1030 static constexpr bool Value = false;
1031 };
1032
1033 template<class T>
1034 struct QmlInterface<T, std::void_t<typename T::QmlIsInterface, decltype(qobject_interface_iid<T *>())>>
1035 {
1036 static constexpr bool Value = bool(T::QmlIsInterface::yes);
1037 };
1038
1039 template<class T, typename = std::void_t<>>
1041 {
1042 static const QMetaObject *staticMetaObject() { return nullptr; }
1043 };
1044
1045 template<class T>
1047 {
1048 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
1049 };
1050
1051 template<class T>
1053 {
1054 static constexpr bool hasAcceptableCtors()
1055 {
1056 if constexpr (!std::is_default_constructible_v<T>)
1057 return false;
1058 else if constexpr (std::is_base_of_v<QObject, T>)
1059 return true;
1060 else
1061 return std::is_copy_constructible_v<T>;
1062 }
1063
1064 static constexpr QMetaType self()
1065 {
1066 if constexpr (std::is_base_of_v<QObject, T>)
1067 return QMetaType::fromType<T*>();
1068 else
1069 return QMetaType::fromType<T>();
1070 }
1071
1072 static constexpr QMetaType list()
1073 {
1074 if constexpr (std::is_base_of_v<QObject, T>)
1075 return QMetaType::fromType<QQmlListProperty<T>>();
1076 else
1077 return QMetaType::fromType<QList<T>>();
1078 }
1079
1080 static constexpr QMetaSequence sequence()
1081 {
1082 if constexpr (std::is_base_of_v<QObject, T>)
1083 return QMetaSequence();
1084 else
1085 return QMetaSequence::fromContainer<QList<T>>();
1086 }
1087
1088 static constexpr int size()
1089 {
1090 return sizeof(T);
1091 }
1092 };
1093
1094 template<>
1095 struct QmlMetaType<void>
1096 {
1097 static constexpr bool hasAcceptableCtors() { return true; }
1098 static constexpr QMetaType self() { return QMetaType(); }
1099 static constexpr QMetaType list() { return QMetaType(); }
1100 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1101 static constexpr int size() { return 0; }
1102 };
1103
1104 template<typename T, typename E, typename WrapperT = T>
1105 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1106 const QMetaObject *classInfoMetaObject,
1107 QVector<int> *qmlTypeIds, const QMetaObject *extension)
1108 {
1109 static_assert(std::is_base_of_v<QObject, T>);
1111 0,
1112
1113 uri,
1114 QTypeRevision::fromMajorVersion(versionMajor),
1115
1116 Constructors<T, WrapperT>::createSingletonInstance,
1117
1118 StaticMetaObject<T>::staticMetaObject(),
1119 classInfoMetaObject,
1120
1121 QmlMetaType<T>::self(),
1122
1123 ExtendedType<E>::createParent,
1124 extension ? extension : ExtendedType<E>::staticMetaObject(),
1125
1126 qmlTypeIds
1127 };
1128
1129 qmlregister(SingletonAndRevisionsRegistration, &api);
1130 }
1131
1132 template<typename T, typename E>
1133 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1134 const QMetaObject *classInfoMetaObject,
1135 QVector<int> *qmlTypeIds, const QMetaObject *extension,
1136 bool forceAnonymous = false)
1137 {
1139 3,
1140 QmlMetaType<T>::self(),
1141 QmlMetaType<T>::list(),
1142 QmlMetaType<T>::size(),
1143 Constructors<T>::createInto,
1144 nullptr,
1145 ValueType<T, E>::create,
1146
1147 uri,
1148 QTypeRevision::fromMajorVersion(versionMajor),
1149
1150 StaticMetaObject<T>::staticMetaObject(),
1151 classInfoMetaObject,
1152
1153 attachedPropertiesFunc<T>(),
1154 attachedPropertiesMetaObject<T>(),
1155
1156 StaticCastSelector<T, QQmlParserStatus>::cast(),
1157 StaticCastSelector<T, QQmlPropertyValueSource>::cast(),
1158 StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
1159
1160 ExtendedType<E>::createParent,
1161 extension ? extension : ExtendedType<E>::staticMetaObject(),
1162
1163 &qmlCreateCustomParser<T>,
1164 qmlTypeIds,
1165 StaticCastSelector<T, QQmlFinalizerHook>::cast(),
1166
1167 forceAnonymous,
1168 QmlMetaType<T>::sequence(),
1169 };
1170
1171 // Initialize the extension so that we can find it by name or ID.
1172 qMetaTypeId<E>();
1173
1174 qmlregister(TypeAndRevisionsRegistration, &type);
1175 }
1176
1177 template<typename T>
1178 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1179 const QMetaObject *classInfoMetaObject,
1180 QVector<int> *qmlTypeIds)
1181 {
1183 0,
1184 uri,
1185 QTypeRevision::fromMajorVersion(versionMajor),
1186 classInfoMetaObject,
1187 QMetaType::fromType<T>(),
1188 QMetaSequence::fromContainer<T>(),
1189 qmlTypeIds
1190 };
1191
1193 }
1194
1195 template<>
1197 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1198 QVector<int> *qmlTypeIds, const QMetaObject *, bool);
1199
1201 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1202 {
1203 return {
1204 /*.revision=*/ 0,
1205 /*.alignment=*/ 0,
1206 /*.size=*/ 0,
1207 /*.flags=*/ 0,
1208 /*.typeId=*/ QBasicAtomicInt(),
1209 /*.metaObject=*/ metaObjectFunction,
1210 /*.name=*/ name,
1211 /*.defaultCtr=*/ nullptr,
1212 /*.copyCtr=*/ nullptr,
1213 /*.moveCtr=*/ nullptr,
1214 /*.dtor=*/ nullptr,
1215 /*.equals*/ nullptr,
1216 /*.lessThan*/ nullptr,
1217 /*.debugStream=*/ nullptr,
1218 /*.dataStreamOut=*/ nullptr,
1219 /*.dataStreamIn=*/ nullptr,
1220 /*.legacyRegisterOp=*/ nullptr
1221 };
1222 }
1223
1224 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1225
1231
1232 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1233
1234 Q_QML_EXPORT QMetaType compositeMetaType(
1236 Q_QML_EXPORT QMetaType compositeMetaType(
1238 Q_QML_EXPORT QMetaType compositeListMetaType(
1240 Q_QML_EXPORT QMetaType compositeListMetaType(
1242
1243} // namespace QQmlPrivate
1244
1245QT_END_NAMESPACE
1246
1247Q_DECLARE_OPAQUE_POINTER(QQmlV4FunctionPtr)
1248Q_DECLARE_OPAQUE_POINTER(QQmlV4ExecutionEnginePtr)
1249
1250#endif // QQMLPRIVATE_H
friend class QJSEngine
static void operator delete(void *ptr)
@ hasAttachedProperties
Definition qqmlprivate.h:76
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())
QObject * createParent(QObject *p)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:48
constexpr QtPrivate::QMetaTypeInterface metaTypeForNamespace(const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
void(*)(void *, void *) CreateIntoFunction
std::is_same< T, typename QmlMarkerFunction< Marker >::ClassType > QmlTypeHasMarker
QObject * createSingletonInstance(QQmlEngine *q, QJSEngine *j)
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset=-1)
void createInto(void *memory, void *)
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:171
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds)
void Q_QML_EXPORT qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds, const QMetaObject *, bool)
Definition qqml.cpp:1116
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
constexpr SingletonConstructionMode singletonConstructionMode()
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
DECLARE_HEAP_OBJECT(DynamicFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(BoundFunction, JavaScriptFunctionObject)
DECLARE_HEAP_OBJECT(ConstructorFunction, ScriptFunction)
DECLARE_HEAP_OBJECT(FunctionObject, Object)
DECLARE_HEAP_OBJECT(JavaScriptFunctionObject, FunctionObject)
DECLARE_HEAP_OBJECT(MemberFunction, ArrowFunction)
DECLARE_HEAP_OBJECT(ScriptFunction, ArrowFunction)
Definition qjsvalue.h:23
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:61
size_t qHash(QByteArrayView key, size_t seed) noexcept
Definition qhash.cpp:875
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:91
QV4::ExecutionEngine * QQmlV4ExecutionEnginePtr
Definition qqmlprivate.h:88
QQmlV4Function * QQmlV4FunctionPtr
Definition qqmlprivate.h:87
DEFINE_OBJECT_VTABLE(SharedArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBufferCtor)
DEFINE_OBJECT_VTABLE(ArrayBuffer)
DEFINE_OBJECT_VTABLE(SharedArrayBuffer)
#define V4_NEEDS_DESTROY
#define Q_MANAGED_TYPE(type)
#define V4_INTERNALCLASS(c)
#define RETURN_UNDEFINED()
void(* functionPtr)(const AOTCompiledContext *context, void **argv)
void(* signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes)
virtual ~AOTTrackedLocalsStorage()=default
virtual void markObjects(QV4::MarkStack *markStack) const =0
const AOTCompiledFunction * aotCompiledFunctions
const QV4::CompiledData::Unit * qmlData
static const QMetaObject * staticMetaObject()
static constexpr const CreateParentFunction createParent
static constexpr bool value
static constexpr bool Value
static QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static Func attachedPropertiesFunc()
static const QMetaObject * staticMetaObject()
static constexpr const QMetaObject * metaObject()
static constexpr bool Value
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr QMetaType list()
static constexpr int size()
static constexpr QMetaType list()
static constexpr QMetaSequence sequence()
static constexpr QMetaType self()
static constexpr bool hasAcceptableCtors()
static constexpr int size()
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
QObject *(* extensionObjectCreate)(QObject *)
std::function< QJSValue(QQmlEngine *, QJSEngine *)> scriptApi
const QMetaObject * extensionMetaObject
const QMetaObject * instanceMetaObject
QObject *(* extensionObjectCreate)(QObject *)
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
QObject *(* extensionObjectCreate)(QObject *)
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 QVariant create(const QJSValue &params)
static constexpr const CreateValueTypeFunction create
static QVariant create(const QJSValue &params)
static ReturnedValue method_isView(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static void virtualCallWithMetaTypes(const FunctionObject *f, QObject *thisObject, void **a, const QMetaType *types, int argc)
static ReturnedValue virtualCall(const QV4::FunctionObject *f, const QV4::Value *thisObject, const QV4::Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static QQmlRefPointer< ExecutableCompilationUnit > parse(ExecutionEngine *engine, const Value *argv, int argc, Type t=Type_Function)
static ReturnedValue method_bind(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_call(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_hasInstance(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_apply(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionContext *scope, Function *function, QV4::String *name=nullptr)
void init(QV4::ExecutionEngine *engine)
void init(QV4::ExecutionEngine *engine, qsizetype index, VTable::Call call)
void init(QV4::ExecutionEngine *engine)
Heap::InternalClass * classForConstructor() const
static ReturnedValue virtualCall(const FunctionObject *f, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
static ReturnedValue method_get_byteLength(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_slice(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue slice(const FunctionObject *b, const Value *thisObject, const Value *argv, int argc, bool shared)