Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
40
42class QQmlContextData;
44
45namespace QQmlPrivate {
46struct CachedQmlUnit;
47template<typename A>
49}
50
51namespace QV4 {
52struct ExecutionEngine;
53class ExecutableCompilationUnit;
54namespace CompiledData {
55struct Unit;
56}
57}
58namespace QmlIR {
59struct Document;
61}
62
64
65inline size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed = 0)
66{
67 return qHash(quintptr(func), seed);
68}
69
70template <typename TYPE>
72{
73public:
74 enum {
76 };
77};
78
79
80class QJSEngine;
81class QQmlEngine;
84
85class QQmlV4Function;
88
89template<class T>
91{
92 return nullptr;
93}
94
95namespace QQmlPrivate
96{
97 void Q_QML_EXPORT qdeclarativeelement_destructor(QObject *);
98 template<typename T>
99 class QQmlElement final : public T
100 {
101 public:
105 static void operator delete(void *ptr) {
106 // We allocate memory from this class in QQmlType::create
107 // along with some additional memory.
108 // So we override the operator delete in order to avoid the
109 // sized operator delete to be called with a different size than
110 // the size that was allocated.
111 ::operator delete (ptr);
112 }
113#ifdef Q_CC_MSVC
114 static void operator delete(void *, void *) {
115 // Deliberately empty placement delete operator.
116 // Silences MSVC warning C4291: no matching operator delete found
117 // On MinGW it causes -Wmismatched-new-delete, though.
118 }
119#endif
120 };
121
123 {
124 None,
126 Factory,
128 };
129
130 template<typename T, typename WrapperT = T, typename = std::void_t<>>
132 {
133 static constexpr bool value = false;
134 };
135
136 template<typename T, typename WrapperT>
137 struct HasSingletonFactory<T, WrapperT, std::void_t<decltype(WrapperT::create(
138 static_cast<QQmlEngine *>(nullptr),
139 static_cast<QJSEngine *>(nullptr)))>>
140 {
141 static constexpr bool value = std::is_same_v<
142 decltype(WrapperT::create(static_cast<QQmlEngine *>(nullptr),
143 static_cast<QJSEngine *>(nullptr))), T *>;
144 };
145
146 template<typename T, typename WrapperT>
148 {
149 if constexpr (!std::is_base_of<QObject, T>::value)
151 if constexpr (!std::is_same_v<T, WrapperT> && HasSingletonFactory<T, WrapperT>::value)
153 if constexpr (std::is_default_constructible<T>::value)
155 if constexpr (HasSingletonFactory<T>::value)
157
159 }
160
161 template<typename>
163
164 template<typename Ret, typename Class>
165 struct QmlMarkerFunction<Ret (Class::*)()>
166 {
167 using ClassType = Class;
168 };
169
170 template<typename T, typename Marker>
171 using QmlTypeHasMarker = std::is_same<T, typename QmlMarkerFunction<Marker>::ClassType>;
172
173 template<typename T>
174 void createInto(void *memory, void *) { new (memory) QQmlElement<T>; }
175
176 template<typename T, typename WrapperT, SingletonConstructionMode Mode>
178 {
179 Q_UNUSED(q);
180 Q_UNUSED(j);
182 return new T;
183 else if constexpr (Mode == SingletonConstructionMode::Factory)
184 return T::create(q, j);
186 return WrapperT::create(q, j);
187 else
188 return nullptr;
189 }
190
191 template<typename T>
192 QObject *createParent(QObject *p) { return new T(p); }
193
194 using CreateIntoFunction = void (*)(void *, void *);
198
199 template<typename T, typename WrapperT = T,
200 SingletonConstructionMode Mode = singletonConstructionMode<T, WrapperT>()>
202
203 template<typename T, typename WrapperT>
204 struct Constructors<T, WrapperT, SingletonConstructionMode::Constructor>
205 {
207 = QQmlPrivate::createInto<T>;
211 };
212
213 template<typename T, typename WrapperT>
215 {
216 static constexpr CreateIntoFunction createInto = nullptr;
218 };
219
220 template<typename T, typename WrapperT>
228
229 template<typename T, typename WrapperT>
237
238 template<typename T,
239 bool IsObject = std::is_base_of<QObject, T>::value,
242
243 template<typename T>
245 {
246 static constexpr const CreateParentFunction createParent = nullptr;
247 static const QMetaObject *staticMetaObject() { return nullptr; }
248 };
249
250 // If it's a QObject, we actually want an error if the ctor or the metaobject is missing.
251 template<typename T>
252 struct ExtendedType<T, true, false>
253 {
254 static constexpr const CreateParentFunction createParent = QQmlPrivate::createParent<T>;
255 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
256 };
257
258 // If it's a Q_GADGET, we don't want the ctor.
259 template<typename T>
260 struct ExtendedType<T, false, true>
261 {
262 static constexpr const CreateParentFunction createParent = nullptr;
263 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
264 };
265
266 template<typename F, typename Result = void>
268 {
269 static constexpr const Result (*create)(const QJSValue &) = nullptr;
270 };
271
272 template<typename F>
273 struct ValueTypeFactory<F, std::void_t<decltype(F::create(QJSValue()))>>
274 {
275 static decltype(F::create(QJSValue())) create(const QJSValue &params)
276 {
277 return F::create(params);
278 }
279 };
280
281 template<typename T, typename F,
282 bool HasCtor = std::is_constructible_v<T, QJSValue>,
283 bool HasFactory = std::is_constructible_v<
285 struct ValueType;
286
287 template<typename T, typename F>
288 struct ValueType<T, F, false, false>
289 {
290 static constexpr const CreateValueTypeFunction create = nullptr;
291 };
292
293 template<typename T, typename F, bool HasCtor>
294 struct ValueType<T, F, HasCtor, true>
295 {
297 {
298 return F::create(params);
299 }
300 };
301
302 template<typename T, typename F>
303 struct ValueType<T, F, true, false>
304 {
306 {
307 return QVariant::fromValue(T(params));
308 }
309 };
310
311 template<class From, class To, int N>
313 {
314 static inline int cast() { return -1; }
315 };
316
317 template<class From, class To>
318 struct StaticCastSelectorClass<From, To, sizeof(int)>
319 {
320 static inline int cast() { return int(reinterpret_cast<quintptr>(static_cast<To *>(reinterpret_cast<From *>(0x10000000)))) - 0x10000000; }
321 };
322
323 template<class From, class To>
325 {
326 typedef int yes_type;
327 typedef char no_type;
328
329 static yes_type checkType(To *);
330 static no_type checkType(...);
331
332 static inline int cast()
333 {
334 return StaticCastSelectorClass<From, To, sizeof(checkType(reinterpret_cast<From *>(0)))>::cast();
335 }
336 };
337
338 // You can prevent subclasses from using the same attached type by specialzing this.
339 // This is reserved for internal types, though.
340 template<class T, class A>
342 {
343 using Type = A;
344 };
345
346 template<class T, class = std::void_t<>, bool OldStyle = QQmlTypeInfo<T>::hasAttachedProperties>
348 {
349 using Type = void;
350 using Func = QQmlAttachedPropertiesFunc<QObject>;
351 static const QMetaObject *staticMetaObject() { return nullptr; }
352 static Func attachedPropertiesFunc() { return nullptr; }
353 };
354
355 // Defined inline via QML_ATTACHED
356 template<class T>
357 struct QmlAttached<T, std::void_t<typename OverridableAttachedType<T, typename T::QmlAttachedType>::Type>, false>
358 {
359 // Normal attached properties
360 template <typename Parent, typename Attached>
361 struct Properties
362 {
363 using Func = QQmlAttachedPropertiesFunc<Attached>;
364 static const QMetaObject *staticMetaObject() { return &Attached::staticMetaObject; }
365 static Func attachedPropertiesFunc() { return Parent::qmlAttachedProperties; }
366 };
367
368 // Disabled via OverridableAttachedType
369 template<typename Parent>
370 struct Properties<Parent, void>
371 {
372 using Func = QQmlAttachedPropertiesFunc<QObject>;
373 static const QMetaObject *staticMetaObject() { return nullptr; }
374 static Func attachedPropertiesFunc() { return nullptr; }
375 };
376
377 using Type = typename std::conditional<
378 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_attached)>::value,
381
383 {
384 return Properties<T, Type>::staticMetaObject();
385 }
386
388 {
389 return Properties<T, Type>::attachedPropertiesFunc();
390 }
391 };
392
393 // Separately defined via QQmlTypeInfo
394 template<class T>
395 struct QmlAttached<T, std::void_t<decltype(T::qmlAttachedProperties)>, true>
396 {
397 using Type = typename std::remove_pointer<decltype(T::qmlAttachedProperties(nullptr))>::type;
398 using Func = QQmlAttachedPropertiesFunc<Type>;
399
400 static const QMetaObject *staticMetaObject() { return &Type::staticMetaObject; }
401 static Func attachedPropertiesFunc() { return T::qmlAttachedProperties; }
402 };
403
404 // This is necessary because both the type containing a default template parameter and the type
405 // instantiating the template need to have access to the default template parameter type. In
406 // this case that's T::QmlAttachedType. The QML_FOREIGN macro needs to befriend specific other
407 // types. Therefore we need some kind of "accessor". Because of compiler bugs in gcc and clang,
408 // we cannot befriend attachedPropertiesFunc() directly. Wrapping the actual access into another
409 // struct "fixes" that. For convenience we still want the free standing functions in addition.
410 template<class T>
412 {
413 static QQmlAttachedPropertiesFunc<QObject> attachedPropertiesFunc()
414 {
415 return QQmlAttachedPropertiesFunc<QObject>(QmlAttached<T>::attachedPropertiesFunc());
416 }
417
419 {
421 }
422 };
423
424 template<typename T>
425 inline QQmlAttachedPropertiesFunc<QObject> attachedPropertiesFunc()
426 {
428 }
429
430 template<typename T>
435
438
440
448
449 bool has(StructVersion v) const { return structVersion >= int(v); }
450
452
456 // The second parameter of create is for userdata
457 void (*create)(void *, void *);
458 void *userdata;
460
461 // ### Qt7: Get rid of this. It can be covered by creationMethod below.
463
464 const char *uri;
466 const char *elementName;
468
469 QQmlAttachedPropertiesFunc<QObject> attachedPropertiesFunction;
471
475
476 QObject *(*extensionObjectCreate)(QObject *);
478
480
483
485 // If this is extended ensure "version" is bumped!!!
486 };
487
522
534
540
559
577
585
593
596 const char *uri;
598
599 // ### Qt7: Remove typeName. It's ignored because the only valid name is "list",
600 // and that's automatic.
601 const char *typeName;
602
606 };
607
619
620 struct Q_QML_EXPORT AOTCompiledContext {
621 enum: uint { InvalidStringId = (std::numeric_limits<uint>::max)() };
622
626 union {
629 };
630
631 QObject *thisObject() const;
632 QQmlEngine *qmlEngine() const;
633
634 QJSValue jsMetaType(int index) const;
635 void setInstructionPointer(int offset) const;
636 void setReturnValueUndefined() const;
637
638 // Run QQmlPropertyCapture::captureProperty() without retrieving the value.
639 bool captureLookup(uint index, QObject *object) const;
640 bool captureQmlContextPropertyLookup(uint index) const;
641 void captureTranslation() const;
642 QString translationContext() const;
643 QMetaType lookupResultMetaType(uint index) const;
644 void storeNameSloppy(uint nameIndex, void *value, QMetaType type) const;
645 QJSValue javaScriptGlobalProperty(uint nameIndex) const;
646
647 const QLoggingCategory *resolveLoggingCategory(QObject *wrapper, bool *ok) const;
648
649 void writeToConsole(
651 const QLoggingCategory *loggingCategory) const;
652
653 QVariant constructValueType(
654 QMetaType resultMetaType, const QMetaObject *resultMetaObject,
655 int ctorIndex, void *ctorArg) const;
656
657 // Those are explicit arguments to the Date() ctor, not implicit coercions.
658 QDateTime constructDateTime(double timestamp) const;
659 QDateTime constructDateTime(const QString &string) const;
661 {
662 return arg.type() == QJSPrimitiveValue::String
663 ? constructDateTime(arg.toString())
664 : constructDateTime(arg.toDouble());
665 }
666
667 QDateTime constructDateTime(
668 double year, double month, double day = 1,
669 double hours = 0, double minutes = 0, double seconds = 0, double msecs = 0) const;
670
671 // All of these lookup functions should be used as follows:
672 //
673 // while (!fooBarLookup(...)) {
674 // setInstructionPointer(...);
675 // initFooBarLookup(...);
676 // if (engine->hasException()) {
677 // ...
678 // break;
679 // }
680 // }
681 //
682 // The bool-returning *Lookup functions exclusively run the happy path and return false if
683 // that fails in any way. The failure may either be in the lookup structs not being
684 // initialized or an exception being thrown.
685 // The init*Lookup functions initialize the lookup structs and amend any exceptions
686 // previously thrown with line numbers. They might also throw their own exceptions. If an
687 // exception is present after the initialization there is no way to carry out the lookup and
688 // the exception should be propagated. If not, the original lookup can be tried again.
689
690 bool callQmlContextPropertyLookup(
691 uint index, void **args, const QMetaType *types, int argc) const;
692 void initCallQmlContextPropertyLookup(uint index) const;
693
694 bool loadContextIdLookup(uint index, void *target) const;
695 void initLoadContextIdLookup(uint index) const;
696
697 bool callObjectPropertyLookup(uint index, QObject *object,
698 void **args, const QMetaType *types, int argc) const;
699 void initCallObjectPropertyLookup(uint index) const;
700
701 bool callGlobalLookup(uint index, void **args, const QMetaType *types, int argc) const;
702 void initCallGlobalLookup(uint index) const;
703
704 bool loadGlobalLookup(uint index, void *target, QMetaType type) const;
705 void initLoadGlobalLookup(uint index) const;
706
707 bool loadScopeObjectPropertyLookup(uint index, void *target) const;
708 bool writeBackScopeObjectPropertyLookup(uint index, void *source) const;
709 void initLoadScopeObjectPropertyLookup(uint index, QMetaType type) const;
710
711 bool loadSingletonLookup(uint index, void *target) const;
712 void initLoadSingletonLookup(uint index, uint importNamespace) const;
713
714 bool loadAttachedLookup(uint index, QObject *object, void *target) const;
715 void initLoadAttachedLookup(uint index, uint importNamespace, QObject *object) const;
716
717 bool loadTypeLookup(uint index, void *target) const;
718 void initLoadTypeLookup(uint index, uint importNamespace) const;
719
720 bool getObjectLookup(uint index, QObject *object, void *target) const;
721 bool writeBackObjectLookup(uint index, QObject *object, void *source) const;
722 void initGetObjectLookup(uint index, QObject *object, QMetaType type) const;
723
724 bool getValueLookup(uint index, void *value, void *target) const;
725 bool writeBackValueLookup(uint index, void *value, void *source) const;
726 void initGetValueLookup(uint index, const QMetaObject *metaObject, QMetaType type) const;
727
728 bool getEnumLookup(uint index, void *target) const;
729#if QT_QML_REMOVED_SINCE(6, 6)
730 bool getEnumLookup(uint index, int *target) const;
731#endif
732 void initGetEnumLookup(uint index, const QMetaObject *metaObject,
733 const char *enumerator, const char *enumValue) const;
734
735 bool setObjectLookup(uint index, QObject *object, void *value) const;
736 void initSetObjectLookup(uint index, QObject *object, QMetaType type) const;
737
738 bool setValueLookup(uint index, void *target, void *value) const;
739 void initSetValueLookup(uint index, const QMetaObject *metaObject, QMetaType type) const;
740 };
741
748
749#if QT_DEPRECATED_SINCE(6, 6)
750 QT_DEPRECATED_VERSION_X(6, 6, "Use AOTCompiledFunction instead")
751 typedef AOTCompiledFunction TypedFunction;
752#endif
753
759
760 typedef const CachedQmlUnit *(*QmlUnitCacheLookupFunction)(const QUrl &url);
765
779
780 int Q_QML_EXPORT qmlregister(RegistrationType, void *);
781 void Q_QML_EXPORT qmlunregister(RegistrationType, quintptr);
782
783#if QT_DEPRECATED_SINCE(6, 3)
784 struct Q_QML_EXPORT SingletonFunctor
785 {
786 QT_DEPRECATED QObject *operator()(QQmlEngine *, QJSEngine *);
787 QPointer<QObject> m_object;
788 bool alreadyCalled = false;
789 };
790#endif
791
792 struct Q_QML_EXPORT SingletonInstanceFunctor
793 {
794 QObject *operator()(QQmlEngine *, QJSEngine *);
795
796 QPointer<QObject> m_object;
797
798 // Not a QPointer, so that you cannot assign it to a different
799 // engine when the first one is deleted.
800 // That would mess up the QML contexts.
801 QQmlEngine *m_engine = nullptr;
802 };
803
804 static int indexOfOwnClassInfo(const QMetaObject *metaObject, const char *key, int startOffset = -1)
805 {
806 if (!metaObject || !key)
807 return -1;
808
809 const int offset = metaObject->classInfoOffset();
810 const int start = (startOffset == -1)
811 ? (metaObject->classInfoCount() + offset - 1)
812 : startOffset;
813 for (int i = start; i >= offset; --i)
814 if (qstrcmp(key, metaObject->classInfo(i).name()) == 0) {
815 return i;
816 }
817 return -1;
818 }
819
820 inline const char *classInfo(const QMetaObject *metaObject, const char *key)
821 {
822 return metaObject->classInfo(indexOfOwnClassInfo(metaObject, key)).value();
823 }
824
826 QTypeRevision defaultValue = QTypeRevision())
827 {
829 return (index == -1) ? defaultValue
831 QLatin1StringView(metaObject->classInfo(index).value()).toInt());
832 }
833
834 Q_QML_EXPORT QList<QTypeRevision> revisionClassInfos(const QMetaObject *metaObject, const char *key);
835
836 inline bool boolClassInfo(const QMetaObject *metaObject, const char *key,
837 bool defaultValue = false)
838 {
840 if (index == -1)
841 return defaultValue;
842 return qstrcmp(metaObject->classInfo(index).value(), "true") == 0;
843 }
844
845 template<class T, class = std::void_t<>>
847 {
848 using Type = void;
849 };
850
851 template<class T>
852 struct QmlExtended<T, std::void_t<typename T::QmlExtendedType>>
853 {
854 using Type = typename std::conditional<
855 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_extended)>::value,
856 typename T::QmlExtendedType, void>::type;
857 };
858
859 template<class T, class = std::void_t<>>
861 {
862 static constexpr const QMetaObject *metaObject() { return nullptr; }
863 };
864
865 template<class T>
866 struct QmlExtendedNamespace<T, std::void_t<decltype(T::qmlExtendedNamespace())>>
867 {
868 static constexpr const QMetaObject *metaObject()
869 {
870 if constexpr (QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_extendedNamespace)>::value)
871 return T::qmlExtendedNamespace();
872 else
873 return nullptr;
874 }
875 };
876
877 template<class T, class = std::void_t<>>
879 {
880 using Type = T;
881 };
882
883 template<class T>
884 struct QmlResolved<T, std::void_t<typename T::QmlForeignType>>
885 {
886 using Type = typename std::conditional<
887 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_foreign)>::value,
888 typename T::QmlForeignType, T>::type;
889 };
890
891 template<class T, class = std::void_t<>>
893 {
894 static constexpr bool Value = false;
895 };
896
897 template<class T>
898 struct QmlUncreatable<T, std::void_t<typename T::QmlIsUncreatable>>
899 {
900 static constexpr bool Value =
901 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_uncreatable)>::value
902 && bool(T::QmlIsUncreatable::yes);
903 };
904
905 template<class T, class = std::void_t<>>
907 {
908 static constexpr bool Value = false;
909 };
910
911 template<class T>
912 struct QmlAnonymous<T, std::void_t<typename T::QmlIsAnonymous>>
913 {
914 static constexpr bool Value =
915 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_anonymous)>::value
916 && bool(T::QmlIsAnonymous::yes);
917 };
918
919
920 template<class T, class = std::void_t<>>
922 {
923 static constexpr bool Value = false;
924 };
925
926 template<class T>
927 struct QmlSingleton<T, std::void_t<typename T::QmlIsSingleton>>
928 {
929 static constexpr bool Value =
930 QmlTypeHasMarker<T, decltype(&T::qt_qmlMarker_singleton)>::value
931 && bool(T::QmlIsSingleton::yes);
932 };
933
934 template<class T, class = std::void_t<>>
936 {
937 static constexpr bool Value = false;
938 };
939
940 template<class T>
941 struct QmlSequence<T, std::void_t<typename T::QmlIsSequence>>
942 {
943 Q_STATIC_ASSERT((std::is_same_v<typename T::QmlSequenceValueType,
945 static constexpr bool Value = bool(T::QmlIsSequence::yes);
946 };
947
948 template<class T, class = std::void_t<>>
950 {
951 static constexpr bool Value = false;
952 };
953
954 template<class T>
955 struct QmlInterface<T, std::void_t<typename T::QmlIsInterface, decltype(qobject_interface_iid<T *>())>>
956 {
957 static constexpr bool Value = bool(T::QmlIsInterface::yes);
958 };
959
960 template<class T, typename = std::void_t<>>
962 {
963 static const QMetaObject *staticMetaObject() { return nullptr; }
964 };
965
966 template<class T>
967 struct StaticMetaObject<T, std::void_t<decltype(T::staticMetaObject)>>
968 {
969 static const QMetaObject *staticMetaObject() { return &T::staticMetaObject; }
970 };
971
972 template<class T>
974 {
975 static constexpr bool hasAcceptableCtors()
976 {
977 if constexpr (!std::is_default_constructible_v<T>)
978 return false;
979 else if constexpr (std::is_base_of_v<QObject, T>)
980 return true;
981 else
982 return std::is_copy_constructible_v<T>;
983 }
984
985 static constexpr QMetaType self()
986 {
987 if constexpr (std::is_base_of_v<QObject, T>)
988 return QMetaType::fromType<T*>();
989 else
990 return QMetaType::fromType<T>();
991 }
992
993 static constexpr QMetaType list()
994 {
995 if constexpr (std::is_base_of_v<QObject, T>)
996 return QMetaType::fromType<QQmlListProperty<T>>();
997 else
998 return QMetaType::fromType<QList<T>>();
999 }
1000
1001 static constexpr QMetaSequence sequence()
1002 {
1003 if constexpr (std::is_base_of_v<QObject, T>)
1004 return QMetaSequence();
1005 else
1006 return QMetaSequence::fromContainer<QList<T>>();
1007 }
1008
1009 static constexpr int size()
1010 {
1011 return sizeof(T);
1012 }
1013 };
1014
1015 template<>
1017 {
1018 static constexpr bool hasAcceptableCtors() { return true; }
1019 static constexpr QMetaType self() { return QMetaType(); }
1020 static constexpr QMetaType list() { return QMetaType(); }
1021 static constexpr QMetaSequence sequence() { return QMetaSequence(); }
1022 static constexpr int size() { return 0; }
1023 };
1024
1025 template<typename T, typename E, typename WrapperT = T>
1026 void qmlRegisterSingletonAndRevisions(const char *uri, int versionMajor,
1027 const QMetaObject *classInfoMetaObject,
1028 QVector<int> *qmlTypeIds, const QMetaObject *extension)
1029 {
1030 static_assert(std::is_base_of_v<QObject, T>);
1032 0,
1033
1034 uri,
1035 QTypeRevision::fromMajorVersion(versionMajor),
1036
1038
1040 classInfoMetaObject,
1041
1043
1046
1047 qmlTypeIds
1048 };
1049
1051 }
1052
1053 template<typename T, typename E>
1054 void qmlRegisterTypeAndRevisions(const char *uri, int versionMajor,
1055 const QMetaObject *classInfoMetaObject,
1056 QVector<int> *qmlTypeIds, const QMetaObject *extension,
1057 bool forceAnonymous = false)
1058 {
1060 3,
1065 nullptr,
1067
1068 uri,
1069 QTypeRevision::fromMajorVersion(versionMajor),
1070
1072 classInfoMetaObject,
1073
1074 attachedPropertiesFunc<T>(),
1075 attachedPropertiesMetaObject<T>(),
1076
1080
1083
1084 &qmlCreateCustomParser<T>,
1085 qmlTypeIds,
1087
1088 forceAnonymous,
1090 };
1091
1092 // Initialize the extension so that we can find it by name or ID.
1093 qMetaTypeId<E>();
1094
1096 }
1097
1098 template<typename T>
1099 void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor,
1100 const QMetaObject *classInfoMetaObject,
1101 QVector<int> *qmlTypeIds)
1102 {
1104 0,
1105 uri,
1106 QTypeRevision::fromMajorVersion(versionMajor),
1107 classInfoMetaObject,
1108 QMetaType::fromType<T>(),
1109 QMetaSequence::fromContainer<T>(),
1110 qmlTypeIds
1111 };
1112
1114 }
1115
1116 template<>
1118 const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject,
1119 QVector<int> *qmlTypeIds, const QMetaObject *, bool);
1120
1122 const QtPrivate::QMetaTypeInterface::MetaObjectFn &metaObjectFunction, const char *name)
1123 {
1124 return {
1125 /*.revision=*/ 0,
1126 /*.alignment=*/ 0,
1127 /*.size=*/ 0,
1128 /*.flags=*/ 0,
1129 /*.typeId=*/ {},
1130 /*.metaObject=*/ metaObjectFunction,
1131 /*.name=*/ name,
1132 /*.defaultCtr=*/ nullptr,
1133 /*.copyCtr=*/ nullptr,
1134 /*.moveCtr=*/ nullptr,
1135 /*.dtor=*/ nullptr,
1136 /*.equals*/ nullptr,
1137 /*.lessThan*/ nullptr,
1138 /*.debugStream=*/ nullptr,
1139 /*.dataStreamOut=*/ nullptr,
1140 /*.dataStreamIn=*/ nullptr,
1141 /*.legacyRegisterOp=*/ nullptr
1142 };
1143 }
1144
1145 Q_QML_EXPORT QObject *qmlExtendedObject(QObject *, int);
1146
1152
1154
1155 Q_QML_EXPORT QMetaType compositeMetaType(
1156 QV4::ExecutableCompilationUnit *unit, const QString &elementName);
1157 Q_QML_EXPORT QMetaType compositeListMetaType(
1158 QV4::ExecutableCompilationUnit *unit, const QString &elementName);
1159
1160} // namespace QQmlPrivate
1161
1163
1166
1167#endif // QQMLPRIVATE_H
\inmodule QtCore\reentrant
Definition qdatetime.h:283
The QJSEngine class provides an environment for evaluating JavaScript code.
Definition qjsengine.h:26
The QJSPrimitiveValue class operates on primitive types in JavaScript semantics.
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
\inmodule QtCore
\inmodule QtCore
\inmodule QtCore
Definition qmetatype.h:341
static constexpr QMetaType fromType()
Definition qmetatype.h:2642
\inmodule QtCore
Definition qobject.h:103
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 QQmlPropertyValueInterceptor class is inherited by property interceptors such as Behavior.
@ hasAttachedProperties
Definition qqmlprivate.h:75
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
static constexpr QTypeRevision fromMajorVersion(Major majorVersion)
Produces a QTypeRevision from the given majorVersion with an invalid minor version.
static constexpr QTypeRevision fromEncodedVersion(Integer value)
Produces a QTypeRevision from the given value.
\inmodule QtCore
Definition qurl.h:94
\inmodule QtCore
Definition qvariant.h:65
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:536
const QMetaObject *(*)(const QMetaTypeInterface *) MetaObjectFn
Definition qmetatype.h:283
void extension()
[6]
Definition dialogs.cpp:230
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:869
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 Q_QML_EXPORT qdeclarativeelement_destructor(QObject *)
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:153
@ CompositeSingletonRegistration
@ SingletonRegistration
@ SequentialContainerRegistration
@ SequentialContainerAndRevisionsRegistration
@ QmlUnitCacheHookRegistration
@ CompositeRegistration
@ SingletonAndRevisionsRegistration
@ InterfaceRegistration
@ AutoParentRegistration
@ TypeAndRevisionsRegistration
void qmlRegisterSequenceAndRevisions(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds)
Q_QML_EXPORT QList< QTypeRevision > revisionClassInfos(const QMetaObject *metaObject, const char *key)
Definition qqml.cpp:901
QQmlAttachedPropertiesFunc< QObject > attachedPropertiesFunc()
@ UnconstructibleSingleton
Q_QML_EXPORT QObject * qmlExtendedObject(QObject *, int)
Definition qqml.cpp:134
constexpr SingletonConstructionMode singletonConstructionMode()
const CachedQmlUnit *(* QmlUnitCacheLookupFunction)(const QUrl &url)
const QMetaObject * attachedPropertiesMetaObject()
const char * classInfo(const QMetaObject *metaObject, const char *key)
bool boolClassInfo(const QMetaObject *metaObject, const char *key, bool defaultValue=false)
QObject *(*)(QQmlEngine *, QJSEngine *) CreateSingletonFunction
int Q_QML_EXPORT qmlregister(RegistrationType, void *)
Definition qqml.cpp:771
QVariant(*)(const QJSValue &) CreateValueTypeFunction
AutoParentResult(* AutoParentFunction)(QObject *object, QObject *parent)
Q_QML_EXPORT QMetaType compositeListMetaType(QV4::ExecutableCompilationUnit *unit, const QString &elementName)
Definition qqml.cpp:187
Q_QML_EXPORT QMetaType compositeMetaType(QV4::ExecutableCompilationUnit *unit, const QString &elementName)
Definition qqml.cpp:179
QObject *(*)(QObject *) CreateParentFunction
void qmlRegisterTypeAndRevisions< QQmlTypeNotAvailable, void >(const char *uri, int versionMajor, const QMetaObject *classInfoMetaObject, QVector< int > *qmlTypeIds, const QMetaObject *extension, bool)
Definition qqml.cpp:923
Combined button and popup list for selecting options.
void(* IRLoaderFunction)(Document *, const QQmlPrivate::CachedQmlUnit *)
Definition qqmlprivate.h:60
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
static ControlElement< T > * ptr(QWidget *widget)
#define Q_DECLARE_OPAQUE_POINTER(POINTER)
Definition qmetatype.h:1517
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
GLsizei GLsizei GLchar * source
void ** params
GLenum func
Definition qopenglext.h:663
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
QQmlEngine * qmlEngine(const QObject *obj)
Definition qqml.cpp:80
static ReturnedValue writeToConsole(const FunctionObject *b, const Value *argv, int argc, ConsoleLogTypes logType, bool printStack=false)
QQmlCustomParser * qmlCreateCustomParser()
Definition qqmlprivate.h:90
size_t qHash(QQmlAttachedPropertiesFunc func, size_t seed=0)
Definition qqmlprivate.h:65
QQmlPrivate::QQmlAttachedPropertiesFunc< QObject > QQmlAttachedPropertiesFunc
Definition qqmlprivate.h:63
QDebug warning(QAnyStringView fileName, int lineNumber)
static Q_CONSTINIT QBasicAtomicInteger< unsigned > seed
Definition qrandom.cpp:196
SSL_CTX int void * arg
#define QT_DEPRECATED_VERSION_X(major, minor, text)
#define QT_DEPRECATED
#define Q_UNUSED(x)
size_t quintptr
Definition qtypes.h:167
unsigned int uint
Definition qtypes.h:34
ptrdiff_t qintptr
Definition qtypes.h:166
QUrl url("example.com")
[constructor-url-reference]
obj metaObject() -> className()
QNetworkRequestFactory api
[0]
view create()
QJSValueList args
\inmodule QtCore
QDateTime constructDateTime(const QJSPrimitiveValue &arg) const
QV4::ExecutableCompilationUnit * compilationUnit
void(* functionPtr)(const AOTCompiledContext *context, void **argv)
void(* signature)(QV4::ExecutableCompilationUnit *unit, QMetaType *argTypes)
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 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()
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)
const QMetaObject * extensionMetaObject
std::function< QJSValue(QQmlEngine *, QJSEngine *) scriptApi)
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:23
void wrapper()