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// Qt-Security score:significant
4
5#ifndef QQMLPRIVATE_H
6#define QQMLPRIVATE_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtQml/qjsprimitivevalue.h>
20#include <QtQml/qjsvalue.h>
21#include <QtQml/qqmllist.h>
22#include <QtQml/qqmlparserstatus.h>
23#include <QtQml/qqmlpropertyvaluesource.h>
24#include <QtQml/qtqmlglobal.h>
25
26#include <QtCore/qdatetime.h>
27#include <QtCore/qdebug.h>
28#include <QtCore/qglobal.h>
29#include <QtCore/qmetasequence.h>
30#include <QtCore/qmetaobject.h>
31#include <QtCore/qpointer.h>
32#include <QtCore/qurl.h>
33#include <QtCore/qvariant.h>
34#include <QtCore/qversionnumber.h>
35
36#include <functional>
37#include <limits>
38#include <type_traits>
39
40QT_BEGIN_NAMESPACE
41
42class QQmlPropertyValueInterceptor;
43class QQmlContextData;
44class QQmlFinalizerHook;
45
46namespace QQmlPrivate {
47struct CachedQmlUnit;
48template<typename A>
49using QQmlAttachedPropertiesFunc = A *(*)(QObject *);
50}
51
52namespace QV4 {
53struct ExecutionEngine;
54struct MarkStack;
55class ExecutableCompilationUnit;
56namespace CompiledData {
57struct Unit;
58}
59}
60namespace QmlIR {
61struct Document;
62typedef void (*IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *);
63}
64
65using QQmlAttachedPropertiesFunc = QQmlPrivate::QQmlAttachedPropertiesFunc<QObject>;
66
67inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
68{
69 return qHash(quintptr(func), seed);
70}
71
72template <typename TYPE>
74{
75public:
76 enum {
78 };
79};
80
81
82class QJSEngine;
83class QQmlEngine;
84class QQmlCustomParser;
86
87class QQmlV4Function;
89using QQmlV4ExecutionEnginePtr = QV4::ExecutionEngine *;
90
91template<class T>
92QQmlCustomParser *qmlCreateCustomParser()
93{
94 return nullptr;
95}
96
97namespace QQmlPrivate
98{
100 template<typename T>
101 class QQmlElement final : public T
102 {
103 public:
104 // Not defaulted so that it can be specialized
106
107 ~QQmlElement() override {
108 QQmlPrivate::qdeclarativeelement_destructor(this);
109 }
110 static void operator delete(void *ptr) {
111 // We allocate memory from this class in QQmlType::create
112 // along with some additional memory.
113 // So we override the operator delete in order to avoid the
114 // sized operator delete to be called with a different size than
115 // the size that was allocated.
116 ::operator delete (ptr);
117 }
118#ifdef Q_CC_MSVC
119 static void operator delete(void *, void *) {
120 // Deliberately empty placement delete operator.
121 // Silences MSVC warning C4291: no matching operator delete found
122 // On MinGW it causes -Wmismatched-new-delete, though.
123 }
124#endif
125 };
126
135
136 template<typename T, typename WrapperT = T, typename = std::void_t<>>
138 {
139 static constexpr bool value = false;
140 };
141
142 template<typename T, typename WrapperT>
144 static_cast<QQmlEngine *>(nullptr),
145 static_cast<QJSEngine *>(nullptr)))>>
146 {
147 static constexpr bool value = std::is_same_v<
148 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
149 static_cast<QJSEngine *>(nullptr))), T *>;
150 };
151
152 template<typename>
154
155 template<typename Ret, typename Class>
156 struct QmlMarkerFunction<Ret (Class::*)()>
157 {
158 using ClassType = Class;
159 };
160
161 template<typename T, typename Marker>
162 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
163
164 template<class T>
166 {
167 private:
168 template<class U>
169 static auto test(int) -> std::enable_if_t<
170 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_uncreatable)>::value
171 && bool(U::QmlIsUncreatable::yes),
172 std::true_type>;
173
174 template<class U>
175 static auto test(...) -> std::false_type;
176
177 public:
178 static constexpr bool Value = decltype(test<T>(0))::value;
179 };
180
181 template<typename T, typename WrapperT>
183 {
184 if constexpr (!std::is_base_of<QObject, T>::value)
186 if constexpr (QmlUncreatable<WrapperT>::Value)
188 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
190 if constexpr (std::is_default_constructible<T>::value)
192 if constexpr (HasSingletonFactory<T>::value)
194
196 }
197
198 template<typename T>
199 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
200
201 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
203 {
204 Q_UNUSED(q);
205 Q_UNUSED(j);
206 if constexpr (Mode == SingletonConstructionMode::Constructor)
207 return new T;
208 else if constexpr (Mode == SingletonConstructionMode::Factory)
209 return T::create(q, j);
210 else if constexpr (Mode == SingletonConstructionMode::FactoryWrapper)
211 return WrapperT::create(q, j);
212 else
213 return nullptr;
214 }
215
216 template<typename T>
217 QObject *createParent(QObject *p) { return new T(p); }
218
219 using CreateIntoFunction = void (*)(void *, void *);
223
224 template<typename T, typename WrapperT = T,
225 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
227
228 template<typename T, typename WrapperT>
230 {
232 = QQmlPrivate::createInto<T>;
234 = QQmlPrivate::createSingletonInstance<
236 };
237
238 template<typename T, typename WrapperT>
240 {
241 static constexpr CreateIntoFunction createInto = nullptr;
243 };
244
245 template<typename T, typename WrapperT>
247 {
248 static constexpr CreateIntoFunction createInto = nullptr;
250 = QQmlPrivate::createSingletonInstance<
252 };
253
254 template<typename T, typename WrapperT>
256 {
257 static constexpr CreateIntoFunction createInto = nullptr;
259 = QQmlPrivate::createSingletonInstance<
261 };
262
263 template<typename T, typename WrapperT>
265 {
266 static constexpr CreateIntoFunction createInto = nullptr;
268 = QQmlPrivate::createSingletonInstance<
270 };
271
272 template<typename T,
276
277 template<typename T>
278 struct ExtendedType<T, false, false>
279 {
280 static constexpr const CreateParentFunction createParent = nullptr;
281 static const QMetaObject *staticMetaObject() { return nullptr; }
282 };
283
284 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
285 template<typename T>
286 struct ExtendedType<T, true, false>
287 {
289 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
290 };
291
292 // If it's a Q_GADGET, we don't want the ctor.
293 template<typename T>
294 struct ExtendedType<T, false, true>
295 {
296 static constexpr const CreateParentFunction createParent = nullptr;
297 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
298 };
299
300 template<typename F, typename Result = void>
302 {
303 static constexpr const Result (*create)(const QJSValue &) = nullptr;
304 };
305
306 template<typename F>
307 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
308 {
309 static decltype(F::create(QJSValue())) create(const QJSValue &params)
310 {
311 return F::create(params);
312 }
313 };
314
315 template<typename T, typename F,
316 bool HasCtor = std::is_constructible_v<T, QJSValue>,
317 bool HasFactory = std::is_constructible_v<
318 QVariant, decltype(ValueTypeFactory<F>::create(QJSValue()))>>
319 struct ValueType;
320
321 template<typename T, typename F>
322 struct ValueType<T, F, false, false>
323 {
324 static constexpr const CreateValueTypeFunction create = nullptr;
325 };
326
327 template<typename T, typename F, bool HasCtor>
328 struct ValueType<T, F, HasCtor, true>
329 {
330 static QVariant create(const QJSValue &params)
331 {
332 return F::create(params);
333 }
334 };
335
336 template<typename T, typename F>
337 struct ValueType<T, F, true, false>
338 {
339 static QVariant create(const QJSValue &params)
340 {
341 return QVariant::fromValue(T(params));
342 }
343 };
344
345 template<class From, class To, int N>
347 {
348 static inline int cast() { return -1; }
349 };
350
351 template<class From, class To>
352 struct StaticCastSelectorClass<From, To, sizeof(int)>
353 {
354 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
355 };
356
357 template<class From, class To>
359 {
360 typedef int yes_type;
361 typedef char no_type;
362
363 static yes_type checkType(To *);
364 static no_type checkType(...);
365
366 static inline int cast()
367 {
368 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
369 }
370 };
371
372 // You can prevent subclasses from using the same attached type by specialzing this.
373 // This is reserved for internal types, though.
374 template<class T, class A>
376 {
377 using Type = A;
378 };
379
380 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
382 {
383 using Type = void;
385 static const QMetaObject *staticMetaObject() { return nullptr; }
386 static Func attachedPropertiesFunc() { return nullptr; }
387 };
388
389 // Defined inline via QML_ATTACHED
390 template<class T>
391 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
392 {
393 // Normal attached properties
394 template <typename Parent, typename Attached>
401
402 // Disabled via OverridableAttachedType
403 template<typename Parent>
404 struct Properties<Parent, void>
405 {
407 static const QMetaObject *staticMetaObject() { return nullptr; }
408 static Func attachedPropertiesFunc() { return nullptr; }
409 };
410
411 using Type = typename std::conditional<
413 typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type, void>::type;
414 using Func = typename Properties<T, Type>::Func;
415
417 {
418 return Properties<T, Type>::staticMetaObject();
419 }
420
422 {
424 }
425 };
426
427 // Separately defined via QQmlTypeInfo
428 template<class T>
429 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
430 {
431 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
433
434 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
436 };
437
438 // This is necessary because both the type containing a default template parameter and the type
439 // instantiating the template need to have access to the default template parameter type. In
440 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
441 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
442 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
443 // struct "fixes" that. For convenience we still want the free standing functions in addition.
444 template<class T>
446 {
448 {
449 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
450 }
451
453 {
454 return QmlAttached<T>::staticMetaObject();
455 }
456 };
457
458 template<typename T>
460 {
461 return QmlAttachedAccessor<T>::attachedPropertiesFunc();
462 }
463
464 template<typename T>
466 {
467 return QmlAttachedAccessor<T>::staticMetaObject();
468 }
469
471 typedef AutoParentResult (*AutoParentFunction)(QObject *object, QObject *parent);
472
474
482
483 bool has(StructVersion v) const { return structVersion >= int(v); }
484
486
490 // The second parameter of create is for userdata
491 void (*create)(void *, void *);
492 void *userdata;
494
495 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
496 QVariant (*createValueType)(const QJSValue &);
497
498 const char *uri;
500 const char *elementName;
502
505
509
512
513 QQmlCustomParser *customParser;
514
517
519 // If this is extended ensure "version" is bumped!!!
520 };
521
556
568
571
572 AutoParentFunction function;
573 };
574
593
611
619
627
630 const char *uri;
632
633 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
634 // and that's automatic.
635 const char *typeName;
636
640 };
641
653
655 {
656 virtual ~AOTTrackedLocalsStorage() = default;
657 virtual void markObjects(QV4::MarkStack *markStack) const = 0;
658 };
659
660 struct Q_QML_EXPORT AOTCompiledContext {
662
666 union {
669 };
670
671 QObject *thisObject() const;
672 QQmlEngine *qmlEngine() const;
673
674 QJSValue jsMetaType(int index) const;
675 void setInstructionPointer(int offset) const;
676 void setLocals(const AOTTrackedLocalsStorage *locals) const;
677 void setReturnValueUndefined() const;
678
679 static void mark(QObject *object, QV4::MarkStack *markStack);
680 static void mark(const QVariant &variant, QV4::MarkStack *markStack);
681 template<typename T>
682 static void mark(T, QV4::MarkStack *) {}
683
684 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
685 bool captureLookup(uint index, QObject *object) const;
687 void captureTranslation() const;
690 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
692
694
695 void writeToConsole(
697 const QLoggingCategory *loggingCategory) const;
698
701 int ctorIndex, void **args) const;
702#if QT_QML_REMOVED_SINCE(6, 9)
705 int ctorIndex, void *ctorArg) const;
706#endif
707
708 // Those are explicit arguments to the Date() ctor, not implicit coercions.
717
719 double year, double month, double day = 1,
720 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
721
722 // All of these lookup functions should be used as follows:
723 //
724 // while (!fooBarLookup(...)) {
725 // setInstructionPointer(...);
726 // initFooBarLookup(...);
727 // if (engine->hasException()) {
728 // ...
729 // break;
730 // }
731 // }
732 //
733 // The bool-returning *Lookup functions exclusively run the happy path and return false if
734 // that fails in any way. The failure may either be in the lookup structs not being
735 // initialized or an exception being thrown.
736 // The init*Lookup functions initialize the lookup structs and amend any exceptions
737 // previously thrown with line numbers. They might also throw their own exceptions. If an
738 // exception is present after the initialization there is no way to carry out the lookup and
739 // the exception should be propagated. If not, the original lookup can be tried again.
740
741 bool callQmlContextPropertyLookup(uint index, void **args, int argc) const;
743
744#if QT_QML_REMOVED_SINCE(6, 9)
746 uint index, void **args, const QMetaType *types, int argc) const;
748#endif
749
750 bool loadContextIdLookup(uint index, void *target) const;
752
753 bool callObjectPropertyLookup(uint index, QObject *object, void **args, int argc) const;
757
758#if QT_QML_REMOVED_SINCE(6, 9)
760 uint index, QObject *object, void **args, const QMetaType *types, int argc) const;
762
763 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
764 void initCallGlobalLookup(uint index) const;
765
766 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
767 void initLoadGlobalLookup(uint index) const;
768#endif
769
770 bool loadGlobalLookup(uint index, void *target) const;
772
776#if QT_QML_REMOVED_SINCE(6, 9)
778#endif
779
780 bool loadSingletonLookup(uint index, void *target) const;
782
783 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
785
786 bool loadTypeLookup(uint index, void *target) const;
788
789 bool getObjectLookup(uint index, QObject *object, void *target) const;
793#if QT_QML_REMOVED_SINCE(6, 9)
795#endif
796
797 bool getValueLookup(uint index, void *value, void *target) const;
798 bool writeBackValueLookup(uint index, void *value, void *source) const;
800#if QT_QML_REMOVED_SINCE(6, 9)
802#endif
803
804 bool getEnumLookup(uint index, void *target) const;
805#if QT_QML_REMOVED_SINCE(6, 6)
806 bool getEnumLookup(uint index, int *target) const;
807#endif
809 const char *enumerator, const char *enumValue) const;
810
811 bool setObjectLookup(uint index, QObject *object, void *value) const;
814#if QT_QML_REMOVED_SINCE(6, 9)
816#endif
817
818 bool setValueLookup(uint index, void *target, void *value) const;
821#if QT_QML_REMOVED_SINCE(6, 9)
823#endif
824
825 bool callValueLookup(uint index, void *target, void **args, int argc) const;
828
835
837 {
838 // This does not cover everything you can possibly wrap into a QVariant.
839 // However, since we only _promise_ to handle single objects, this is OK.
841 return;
842
843 if (QObject *object = *static_cast<QObject *const *>(variant.constData()))
845 }
846
847 template<typename Value>
849 };
850
854 void (*signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes);
855 void (*functionPtr)(const AOTCompiledContext *context, void **argv);
856 };
857
858#if QT_DEPRECATED_SINCE(6, 6)
859 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
861#endif
862
868
869 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
872 QmlUnitCacheLookupFunction lookupCachedQmlUnit;
873 };
874
888
891
892#if QT_DEPRECATED_SINCE(6, 3)
894 {
897 bool alreadyCalled = false;
898 };
899#endif
900
901 struct Q_QML_EXPORT SingletonInstanceFunctor
902 {
904
906
907 // Not a QPointer, so that you cannot assign it to a different
908 // engine when the first one is deleted.
909 // That would mess up the QML contexts.
911 };
912
913 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
914 {
915 if (!metaObject || !key)
916 return -1;
917
918 const int offset = metaObject->classInfoOffset();
919 const int start = (startOffset == -1)
920 ? (metaObject->classInfoCount() + offset - 1)
921 : startOffset;
922 for (int i = start; i >= offset; --i)
923 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
924 return i;
925 }
926 return -1;
927 }
928
929 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
930 {
931 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
932 }
933
934 inline QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key,
935 QTypeRevision defaultValue = QTypeRevision())
936 {
937 const int index = indexOfOwnClassInfo(metaObject, key);
938 return (index == -1) ? defaultValue
939 : QTypeRevision::fromEncodedVersion(
940 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
941 }
942
944
945 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
946 bool defaultValue = false)
947 {
948 const int index = indexOfOwnClassInfo(metaObject, key);
949 if (index == -1)
950 return defaultValue;
951 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
952 }
953
954 // These detector classes are using a somehow "old school" SFINAE
955 // approach (overloaded test() functions, rather than void_t
956 // and similar more modern constructs) to avoid hitting GCC/MSVC
957 // bugs; be careful when refactoring these. In particular, make sure
958 // that they still work with private members even if you befriend
959 // the detector.
960
961 template<class T>
963 {
964 private:
965 template<class U>
966 static auto test(int) -> std::conditional_t<
967 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extended)>::value,
968 typename U::QmlExtendedType *,
969 void *
970 >;
971
972 template<class U>
973 static auto test(...) -> void *;
974
975 public:
976 // Some compilers complain if we have functions return abstract types.
977 // So we add pointers in the above, and remove the pointer here.
978 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
979 };
980
981 template<class T>
983 {
984 private:
985 template<class U>
986 static constexpr auto metaObjectImpl(int) ->
987 decltype((void)U::qmlExtendedNamespace(), static_cast<const QMetaObject *>(nullptr))
988 {
989 if constexpr (QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_extendedNamespace)>::value)
990 return U::qmlExtendedNamespace();
991 else
992 return nullptr;
993 }
994
995 template<class U>
996 static constexpr auto metaObjectImpl(...) -> const QMetaObject *
997 {
998 return nullptr;
999 }
1000
1001 public:
1002 static constexpr const QMetaObject *metaObject() { return metaObjectImpl<T>(0); }
1003 };
1004
1005 template<class T>
1007 {
1008 private:
1009 template<class U>
1010 static auto test(int) -> std::conditional_t<
1011 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_foreign)>::value,
1012 typename U::QmlForeignType *,
1013 U *
1014 >;
1015
1016 template<class U>
1017 static auto test(...) -> U *;
1018
1019 public:
1020 using Type = std::remove_pointer_t<decltype(test<T>(0))>;
1021 };
1022
1023 template<class T>
1025 {
1026 private:
1027 template<class U>
1028 static auto test(int) -> std::enable_if_t<
1029 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_anonymous)>::value
1030 && bool(U::QmlIsAnonymous::yes),
1031 std::true_type
1032 >;
1033
1034 template<class U>
1035 static auto test(...) -> std::false_type;
1036
1037 public:
1038 static constexpr bool Value = decltype(test<T>(0))::value;
1039 };
1040
1041 template <class T>
1043 {
1044 private:
1045 template<class U>
1046 static auto test(int) -> std::enable_if_t<
1047 QmlTypeHasMarker<U, decltype(&U::qt_qmlMarker_singleton)>::value
1048 && bool(U::QmlIsSingleton::yes),
1049 std::true_type
1050 >;
1051
1052 template<class U>
1053 static auto test(...) -> std::false_type;
1054
1055 public:
1056 static constexpr bool Value = decltype(test<T>(0))::value;
1057 };
1058
1059 template<class T>
1061 {
1062 private:
1063 template<class U>
1064 static auto test_impl(int) -> std::bool_constant<bool(U::QmlIsSequence::yes)>;
1065
1066 template<class U>
1067 static auto test_impl(...) -> std::false_type;
1068
1069 template<class U>
1070 static constexpr bool test() {
1071 if constexpr (decltype(test_impl<U>(0))::value) {
1072 static_assert((std::is_same_v<typename U::QmlSequenceValueType,
1073 typename QmlResolved<U>::Type::value_type>));
1074 return true;
1075 }
1076 return false;
1077 }
1078
1079 public:
1080 static constexpr bool Value = test<T>();
1081 };
1082
1083 template<class T>
1085 {
1086 private:
1087 template<class U>
1088 static auto test(int) ->
1089 decltype((void)qobject_interface_iid<U *>(), std::bool_constant<bool(U::QmlIsInterface::yes)>{});
1090
1091 template<class U>
1092 static auto test(...) -> std::false_type;
1093
1094 public:
1095 static constexpr bool Value = decltype(test<T>(0))::value;
1096 };
1097
1098 template<class T, typename = std::void_t<>>
1100 {
1101 static const QMetaObject *staticMetaObject() { return nullptr; }
1102 };
1103
1104 template<class T>
1106 {
1107 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
1108 };
1109
1110 template<class T>
1112 {
1113 static constexpr bool hasAcceptableCtors()
1114 {
1115 if constexpr (!std::is_default_constructible_v<T>)
1116 return false;
1117 else if constexpr (std::is_base_of_v<QObject, T>)
1118 return true;
1119 else
1120 return std::is_copy_constructible_v<T>;
1121 }
1122
1123 static constexpr QMetaType self()
1124 {
1125 if constexpr (std::is_base_of_v<QObject, T>)
1126 return QMetaType::fromType<T*>();
1127 else
1128 return QMetaType::fromType<T>();
1129 }
1130
1131 static constexpr QMetaType list()
1132 {
1133 if constexpr (std::is_base_of_v<QObject, T>)
1134 return QMetaType::fromType<QQmlListProperty<T>>();
1135 else
1136 return QMetaType::fromType<QList<T>>();
1137 }
1138
1139 static constexpr QMetaSequence sequence()
1140 {
1141 if constexpr (std::is_base_of_v<QObject, T>)
1142 return QMetaSequence();
1143 else
1144 return QMetaSequence::fromContainer<QList<T>>();
1145 }
1146
1147 static constexpr int size()
1148 {
1149 return sizeof(T);
1150 }
1151 };
1152
1153 template<>
1154 struct QmlMetaType<void>
1155 {
1156 static constexpr bool hasAcceptableCtors() { return true; }
1157 static constexpr QMetaType self() { return QMetaType(); }
1158 static constexpr QMetaType list() { return QMetaType(); }
1159 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1160 static constexpr int size() { return 0; }
1161 };
1162
1163 template<typename T, typename E, typename WrapperT = T>
1164 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1165 const QMetaObject *classInfoMetaObject,
1166 QList<int> *qmlTypeIds, const QMetaObject *extension)
1167 {
1168 static_assert(std::is_base_of_v<QObject, T>);
1170 0,
1171
1172 uri,
1173 QTypeRevision::fromMajorVersion(versionMajor),
1174
1175 Constructors<T, WrapperT>::createSingletonInstance,
1176
1177 StaticMetaObject<T>::staticMetaObject(),
1178 classInfoMetaObject,
1179
1180 QmlMetaType<T>::self(),
1181
1182 ExtendedType<E>::createParent,
1183 extension ? extension : ExtendedType<E>::staticMetaObject(),
1184
1185 qmlTypeIds
1186 };
1187
1188 qmlregister(SingletonAndRevisionsRegistration, &api);
1189 }
1190
1191 template<typename T, typename E>
1192 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1193 const QMetaObject *classInfoMetaObject,
1194 QList<int> *qmlTypeIds, const QMetaObject *extension,
1195 bool forceAnonymous = false)
1196 {
1198 3,
1199 QmlMetaType<T>::self(),
1200 QmlMetaType<T>::list(),
1201 QmlMetaType<T>::size(),
1202 Constructors<T>::createInto,
1203 nullptr,
1204 ValueType<T, E>::create,
1205
1206 uri,
1207 QTypeRevision::fromMajorVersion(versionMajor),
1208
1209 StaticMetaObject<T>::staticMetaObject(),
1210 classInfoMetaObject,
1211
1212 attachedPropertiesFunc<T>(),
1213 attachedPropertiesMetaObject<T>(),
1214
1215 StaticCastSelector<T, QQmlParserStatus>::cast(),
1216 StaticCastSelector<T, QQmlPropertyValueSource>::cast(),
1217 StaticCastSelector<T, QQmlPropertyValueInterceptor>::cast(),
1218
1219 ExtendedType<E>::createParent,
1220 extension ? extension : ExtendedType<E>::staticMetaObject(),
1221
1222 &qmlCreateCustomParser<T>,
1223 qmlTypeIds,
1224 StaticCastSelector<T, QQmlFinalizerHook>::cast(),
1225
1226 forceAnonymous,
1227 QmlMetaType<T>::sequence(),
1228 };
1229
1230 // Initialize the extension so that we can find it by name or ID.
1231 qMetaTypeId<E>();
1232
1233 qmlregister(TypeAndRevisionsRegistration, &type);
1234 }
1235
1236 template<typename T>
1237 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1238 const QMetaObject *classInfoMetaObject,
1239 QList<int> *qmlTypeIds)
1240 {
1242 0,
1243 uri,
1244 QTypeRevision::fromMajorVersion(versionMajor),
1245 classInfoMetaObject,
1246 QMetaType::fromType<T>(),
1247 QMetaSequence::fromContainer<T>(),
1248 qmlTypeIds
1249 };
1250
1252 }
1253
1254 template<>
1256 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1257 QList<int> *qmlTypeIds, const QMetaObject *, bool);
1258
1260 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1261 {
1262 return {
1263 /*.revision=*/ 0,
1264 /*.alignment=*/ 0,
1265 /*.size=*/ 0,
1266 /*.flags=*/ 0,
1267 /*.typeId=*/ QBasicAtomicInt(),
1268 /*.metaObject=*/ metaObjectFunction,
1269 /*.name=*/ name,
1270 /*.defaultCtr=*/ nullptr,
1271 /*.copyCtr=*/ nullptr,
1272 /*.moveCtr=*/ nullptr,
1273 /*.dtor=*/ nullptr,
1274 /*.equals*/ nullptr,
1275 /*.lessThan*/ nullptr,
1276 /*.debugStream=*/ nullptr,
1277 /*.dataStreamOut=*/ nullptr,
1278 /*.dataStreamIn=*/ nullptr,
1279 /*.legacyRegisterOp=*/ nullptr
1280 };
1281 }
1282
1283 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1284
1290
1291 Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type);
1292
1293 Q_QML_EXPORT QMetaType compositeMetaType(
1295 Q_QML_EXPORT QMetaType compositeMetaType(
1297 Q_QML_EXPORT QMetaType compositeListMetaType(
1299 Q_QML_EXPORT QMetaType compositeListMetaType(
1301
1302} // namespace QQmlPrivate
1303
1304QT_END_NAMESPACE
1305
1306Q_DECLARE_OPAQUE_POINTER(QQmlV4FunctionPtr)
1307Q_DECLARE_OPAQUE_POINTER(QQmlV4ExecutionEnginePtr)
1308
1309#endif // QQMLPRIVATE_H
void operator delete(void *)
friend class QJSEngine
static void operator delete(void *ptr)
@ hasAttachedProperties
Definition qqmlprivate.h:77
QTypeRevision revisionClassInfo(const QMetaObject *metaObject, const char *key, QTypeRevision defaultValue=QTypeRevision())
QObject * createParent(QObject *p)
A *(*)(QObject *) QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:49
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)
void Q_QML_EXPORT qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *, bool)
Definition qqml.cpp:1119
static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset=-1)
void createInto(void *memory, void *)
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds)
Q_QML_EXPORT void qmlRegistrationWarning(QmlRegistrationWarning warning, QMetaType type)
Definition qqml.cpp:172
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
constexpr SingletonConstructionMode singletonConstructionMode()
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension)
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QList< int > *qmlTypeIds, const QMetaObject *extension, bool forceAnonymous=false)
Combined button and popup list for selecting options.
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:24
ReturnedValue checkedResult(QV4::ExecutionEngine *v4, ReturnedValue result)
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:62
size_t qHash(QByteArrayView key, size_t seed) noexcept
Definition qhash.cpp:876
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:92
QV4::ExecutionEngine * QQmlV4ExecutionEnginePtr
Definition qqmlprivate.h:89
QQmlV4Function * QQmlV4FunctionPtr
Definition qqmlprivate.h:88
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)