12#include <qcoreapplication.h>
13#include <QtCore/qspan.h>
19#include "private/qthread_p.h"
21#include "private/qlatch_p.h"
25#include "private/qmetaobject_moc_p.h"
34using namespace Qt::StringLiterals;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
114
115
116
117
118
119
120
121
128 Q_ASSERT(priv(mo->d.data)->revision >= 7);
129 uint offset = mo->d.stringdata[2*index];
130 return reinterpret_cast<
const char *>(mo->d.stringdata) + offset;
135 Q_ASSERT(priv(mo->d.data)->revision >= 7);
136 uint offset = mo->d.stringdata[2*index];
137 uint length = mo->d.stringdata[2*index + 1];
138 const char *string =
reinterpret_cast<
const char *>(mo->d.stringdata) + offset;
139 return {string, qsizetype(length)};
144 if (QMetaObjectPrivate::get(mo)->flags & AllocatedMetaObject) {
146 return view.toByteArray();
151 return QByteArray::fromRawData(view.data(), view.size());
156 return stringData(mo, stringDataView(mo, index));
161 if (typeInfo & IsUnresolvedType)
162 return stringDataView(mo, typeInfo & TypeNameIndexMask);
164 return QByteArrayView(QMetaType(typeInfo).name());
169 if (!(typeInfo & IsUnresolvedType))
171 return qMetaTypeTypeInternal(stringDataView(mo, typeInfo & TypeNameIndexMask));
177 std::optional<QByteArrayView> scope;
180 if (qualifiedKey.startsWith(
"QFlags<") && qualifiedKey.endsWith(
'>'))
181 qualifiedKey.slice(7, qualifiedKey.length() - 8);
182 const auto scopePos = qualifiedKey.lastIndexOf(
"::"_L1);
184 return R{
std::nullopt, qualifiedKey};
186 return R{qualifiedKey.first(scopePos), qualifiedKey.sliced(scopePos + 2)};
193 static const QMetaMethodPrivate *get(
const QMetaMethod *q)
194 {
return static_cast<
const QMetaMethodPrivate *>(q); }
197 inline QByteArrayView qualifiedName()
const noexcept;
198 inline QByteArrayView name()
const noexcept;
199 inline int typesDataIndex()
const;
200 inline const char *rawReturnTypeName()
const;
201 inline int returnType()
const;
202 inline int parameterCount()
const;
203 inline int parametersDataIndex()
const;
204 inline uint parameterTypeInfo(
int index)
const;
205 inline int parameterType(
int index)
const;
206 inline void getParameterTypes(
int *types)
const;
209 inline QByteArrayView parameterTypeName(
int index)
const noexcept;
210 inline QList<QByteArray> parameterTypes()
const;
211 inline QList<QByteArray> parameterNames()
const;
212 inline const char *tag()
const;
213 inline int ownMethodIndex()
const;
214 inline int ownConstructorMethodIndex()
const;
218 QMetaMethodPrivate();
224#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
226
227
228
229
230
231
232
233
234
235
236
237
238
239QObject *QMetaObject::newInstance(QGenericArgument val0,
240 QGenericArgument val1,
241 QGenericArgument val2,
242 QGenericArgument val3,
243 QGenericArgument val4,
244 QGenericArgument val5,
245 QGenericArgument val6,
246 QGenericArgument val7,
247 QGenericArgument val8,
248 QGenericArgument val9)
const
250 const char *typeNames[] = {
252 val0.name(), val1.name(), val2.name(), val3.name(), val4.name(),
253 val5.name(), val6.name(), val7.name(), val8.name(), val9.name()
255 const void *parameters[] = {
257 val0.data(), val1.data(), val2.data(), val3.data(), val4.data(),
258 val5.data(), val6.data(), val7.data(), val8.data(), val9.data()
262 for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
263 int len =
int(qstrlen(typeNames[paramCount]));
268 return newInstanceImpl(
this, paramCount, parameters, typeNames,
nullptr);
273
274
275
276
277
278
279
280
281
282
283
284
285
287QObject *QMetaObject::newInstanceImpl(
const QMetaObject *mobj, qsizetype paramCount,
288 const void **parameters,
const char **typeNames,
289 const QtPrivate::QMetaTypeInterface **metaTypes)
291 if (!mobj->inherits(&QObject::staticMetaObject)) {
292 qWarning(
"QMetaObject::newInstance: type %s does not inherit QObject", mobj->className());
298QT_WARNING_DISABLE_GCC(
"-Wdangling-pointer")
302 QObject *returnValue =
nullptr;
303 QMetaType returnValueMetaType = QMetaType::fromType<
decltype(returnValue)>();
304 parameters[0] = &returnValue;
305 typeNames[0] = returnValueMetaType.name();
307 metaTypes[0] = returnValueMetaType.iface();
312 auto priv = QMetaObjectPrivate::get(mobj);
313 for (
int i = 0; i < priv->constructorCount; ++i) {
314 QMetaMethod m = QMetaMethod::fromRelativeConstructorIndex(mobj, i);
315 if (m.parameterCount() != (paramCount - 1))
319 QMetaMethodPrivate::InvokeFailReason r =
320 QMetaMethodPrivate::invokeImpl(m,
nullptr, Qt::DirectConnection, paramCount,
321 parameters, typeNames, metaTypes);
322 if (r == QMetaMethodPrivate::InvokeFailReason::None)
332
333
334int QMetaObject::static_metacall(Call cl,
int idx,
void **argv)
const
336 Q_ASSERT(priv(d.data)->revision >= 6);
337 if (!d.static_metacall)
339 d.static_metacall(
nullptr, cl, idx, argv);
344
345
346int QMetaObject::metacall(QObject *object, Call cl,
int idx,
void **argv)
348 if (object->d_ptr->metaObject)
349 return object->d_ptr->metaObject->metaCall(object, cl, idx, argv);
351 return object->qt_metacall(cl, idx, argv);
356 return stringDataView(m, priv(m->d.data)->className);
360
361
362
363
364const char *QMetaObject::className()
const
366 return objectClassName(
this).constData();
370
371
372
373
374
375
376
379
380
381
382
383
384
385
386bool QMetaObject::inherits(
const QMetaObject *metaObject)
const noexcept
388 const QMetaObject *m =
this;
392 }
while ((m = m->d.superdata));
397
398
399
400
401
402
405
406
407
408
409
410const QObject *QMetaObject::cast(
const QObject *obj)
const
412 return (obj && obj->metaObject()->inherits(
this)) ? obj :
nullptr;
415#ifndef QT_NO_TRANSLATION
417
418
419QString QMetaObject::tr(
const char *s,
const char *c,
int n)
const
421 return QCoreApplication::translate(className(), s, c, n);
426
427
428
429
430QMetaType QMetaObject::metaType()
const
433 const QMetaObjectPrivate *d = priv(
this->d.data);
434 if (d->revision < 10) {
436 return QMetaType::fromName(className());
439
440
441
442
443
444
445
446
447
448
449
450
451#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
455 const qsizetype offset = d->revision < 12
457 : d->propertyCount + d->enumeratorCount;
459 const qsizetype offset = d->propertyCount + d->enumeratorCount;
462 auto iface =
this->d.metaTypes[offset];
463 if (iface && QtMetaTypePrivate::isInterfaceFor<
void>(iface))
466 return QMetaType(iface);
468 return QMetaType::fromName(className());
473
474
475
476
477
478
479
480
481
482int QMetaObject::methodOffset()
const
485 const QMetaObject *m = d.superdata;
487 offset += priv(m->d.data)->methodCount;
495
496
497
498
499
500
501
502
503
504int QMetaObject::enumeratorOffset()
const
507 const QMetaObject *m = d.superdata;
509 offset += priv(m->d.data)->enumeratorCount;
516
517
518
519
520
521
522
523
524
525int QMetaObject::propertyOffset()
const
528 const QMetaObject *m = d.superdata;
530 offset += priv(m->d.data)->propertyCount;
537
538
539
540
541
542
543
544
545
546int QMetaObject::classInfoOffset()
const
549 const QMetaObject *m = d.superdata;
551 offset += priv(m->d.data)->classInfoCount;
558
559
560
561
562
563
564int QMetaObject::constructorCount()
const
566 Q_ASSERT(priv(d.data)->revision >= 2);
567 return priv(d.data)->constructorCount;
571
572
573
574
575
576
577
578
579
580
581
582int QMetaObject::methodCount()
const
584 int n = priv(d.data)->methodCount;
585 const QMetaObject *m = d.superdata;
587 n += priv(m->d.data)->methodCount;
594
595
596
597
598int QMetaObject::enumeratorCount()
const
600 int n = priv(d.data)->enumeratorCount;
601 const QMetaObject *m = d.superdata;
603 n += priv(m->d.data)->enumeratorCount;
610
611
612
613
614
615
616
617
618
619
620int QMetaObject::propertyCount()
const
622 int n = priv(d.data)->propertyCount;
623 const QMetaObject *m = d.superdata;
625 n += priv(m->d.data)->propertyCount;
632
633
634
635
636int QMetaObject::classInfoCount()
const
638 int n = priv(d.data)->classInfoCount;
639 const QMetaObject *m = d.superdata;
641 n += priv(m->d.data)->classInfoCount;
652 QSpan<
const QArgumentType> types)
654 const qsizetype argc = types.size();
655 const QMetaMethod::Data &data = method.data;
656 auto priv = QMetaMethodPrivate::get(&method);
657 if (priv->parameterCount() != argc)
662 if (
const auto qname = priv->qualifiedName(); !qname.endsWith(name))
664 else if (
const auto n = qname.chopped(name.size()); !n.isEmpty() && !n.endsWith(
':'))
668 int paramsIndex = data.parameters() + 1;
669 for (qsizetype i = 0; i < argc; ++i) {
670 uint typeInfo = m->d.data[paramsIndex + i];
673 if (mt == QMetaType(ifaces[i]))
675 if (mt.id() != typeFromTypeInfo(m, typeInfo))
678 if (types[i].name() == QMetaType(ifaces[i]).name())
680 if (types[i].name() != typeNameFromTypeInfo(m, typeInfo))
689
690
691
694 for (
const QMetaObject *currentObject = baseObject; currentObject; currentObject = currentObject->superClass()) {
695 const int start = priv(currentObject->d.data)->methodCount - 1;
697 for (
int i = start; i >= end; --i) {
698 auto candidate = QMetaMethod::fromRelativeMethodIndex(currentObject, i);
699 if (name == candidate.name())
703 return QMetaMethod{};
707
708
709
710
711
712
713
716 QSpan<
const QArgumentType> types,
717 QMetaMethod::MethodType what)
719 for (
const QMetaObject *m = *baseObject; m; m = m->d.superdata) {
720 Q_ASSERT(priv(m->d.data)->revision >= 7);
724 case QMetaMethod::Signal:
725 i = priv(m->d.data)->signalCount - 1;
727 case QMetaMethod::Slot:
728 i = priv(m->d.data)->methodCount - 1;
729 end = priv(m->d.data)->signalCount;
731 case QMetaMethod::Method:
732 i = priv(m->d.data)->methodCount - 1;
734 case QMetaMethod::Constructor:
735 Q_UNREACHABLE_RETURN(-1);
739 for (; i >= end; --i) {
740 auto data = QMetaMethod::fromRelativeMethodIndex(m, i);
741 if (methodMatch(m, data, name, types)) {
742 if (QT_VERSION >= QT_VERSION_CHECK(7, 0, 0)
743 && what == QMetaMethod::Slot && data.methodType() != QMetaMethod::Slot) {
756
757
758
759
760
761
762
763
764
765
767#if QT_DEPRECATED_SINCE(6
, 10
)
769static int compat_indexOf(
const char *what,
const char *sig,
const QMetaObject *mo,
770 int (*indexOf)(
const QMetaObject *,
const char *))
772 const QByteArray normalized = QByteArray(sig).replace(
"QVector<",
"QList<");
773 const int i = indexOf(mo, normalized.data());
775 qWarning(R"(QMetaObject::indexOf%s: argument "%s" is not normalized, because it contains "QVector<". )"
776 R"(Earlier versions of Qt 6 incorrectly normalized QVector< to QList<, silently. )"
777 R"(This behavior is deprecated as of 6.10, and will be removed in a future version of Qt.)",
783#define INDEXOF_COMPAT(what, arg)
785 if (i < 0
&& Q_UNLIKELY(std::strstr(arg, "QVector<")))
786 i = compat_indexOf(#what, arg, this, &indexOf ## what ## _helper);
789#define INDEXOF_COMPAT(what, arg)
795 QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(constructor, types);
796 return QMetaObjectPrivate::indexOfConstructor(mo, name, types);
799int QMetaObject::indexOfConstructor(
const char *constructor)
const
801 Q_ASSERT(priv(d.data)->revision >= 7);
802 int i = indexOfConstructor_helper(
this, constructor);
808
809
810
811
812
813
814
815
816
820 Q_ASSERT(priv(m->d.data)->revision >= 7);
822 QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(method, types);
823 return QMetaObjectPrivate::indexOfMethod(m, name, types);
826int QMetaObject::indexOfMethod(
const char *method)
const
828 int i = indexOfMethod_helper(
this, method);
834
835
836
837
838
839
843 Q_ASSERT(types.isEmpty());
844 QVarLengthArray<QByteArrayView, 10> typeNames;
845 QByteArrayView name = parameterTypeNamesFromSignature(signature, typeNames);
846 for (
auto type : typeNames)
847 types.emplace_back(type);
852
853
854
855
856
857
858
859
860
861
862
863
867 Q_ASSERT(priv(m->d.data)->revision >= 7);
869 QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(signal, types);
870 return QMetaObjectPrivate::indexOfSignal(m, name, types);
873int QMetaObject::indexOfSignal(
const char *signal)
const
875 int i = indexOfSignal_helper(
this, signal);
881
882
883
884
885
888 QSpan<
const QArgumentType> types)
890 int i = indexOfMethodRelative(baseObject, name, types, QMetaMethod::Signal);
892 const QMetaObject *m = *baseObject;
893 if (i >= 0 && m && m->d.superdata) {
894 int conflict = indexOfMethod(m->d.superdata, name, types);
896 QMetaMethod conflictMethod = m->d.superdata->method(conflict);
897 qWarning(
"QMetaObject::indexOfSignal: signal %s from %s redefined in %s",
898 conflictMethod.methodSignature().constData(),
899 m->d.superdata->className(), m->className());
907
908
909
910
911
912
913
914
915
919 Q_ASSERT(priv(m->d.data)->revision >= 7);
921 QByteArrayView name = QMetaObjectPrivate::decodeMethodSignature(slot, types);
922 return QMetaObjectPrivate::indexOfSlot(m, name, types);
925int QMetaObject::indexOfSlot(
const char *slot)
const
927 int i = indexOfSlot_helper(
this, slot);
937 QSpan<
const QArgumentType> types)
939 return indexOfMethodRelative(m, name, types, QMetaMethod::Slot);
943 QSpan<
const QArgumentType> types)
945 int i = indexOfSignalRelative(&m, name, types);
947 i += m->methodOffset();
952 QSpan<
const QArgumentType> types)
954 int i = indexOfSlotRelative(&m, name, types);
956 i += m->methodOffset();
961 QSpan<
const QArgumentType> types)
963 int i = indexOfMethodRelative(&m, name, types, QMetaMethod::Method);
965 i += m->methodOffset();
970 QSpan<
const QArgumentType> types)
972 for (
int i = priv(m->d.data)->constructorCount-1; i >= 0; --i) {
973 const QMetaMethod method = QMetaMethod::fromRelativeConstructorIndex(m, i);
974 if (methodMatch(m, method, name, types))
981
982
983
984
985
986
987
988
989
990
993
994
995
996
997
998
999
1000
1001
1004 Q_ASSERT(m !=
nullptr);
1005 int n = priv(m->d.data)->signalCount;
1006 for (m = m->d.superdata; m; m = m->d.superdata)
1007 n += priv(m->d.data)->signalCount;
1012
1013
1014
1015
1016
1017
1018
1019
1024 return QMetaMethodPrivate::get(&m)->ownMethodIndex() + signalOffset(m.mobj);
1028
1029
1030
1031
1032
1033
1034
1035
1038 if (signal_index < 0)
1039 return QMetaMethod();
1041 Q_ASSERT(m !=
nullptr);
1042 int i = signal_index;
1043 i -= signalOffset(m);
1044 if (i < 0 && m->d.superdata)
1045 return signal(m->d.superdata, signal_index);
1048 if (i >= 0 && i < priv(m->d.data)->signalCount)
1049 return QMetaMethod::fromRelativeMethodIndex(m, i);
1050 return QMetaMethod();
1054
1055
1056
1057
1058
1060 QSpan<
const QArgumentType> methodTypes)
1062 const qsizetype methodArgc = methodTypes.size();
1063 if (signalTypes.size() >= methodArgc) {
1064 signalTypes = signalTypes.first(methodArgc);
1065 return std::equal(signalTypes.begin(), signalTypes.end(),
1066 methodTypes.begin(), methodTypes.end());
1072
1073
1074
1075
1076
1078 const QMetaMethodPrivate *method)
1080 if (signal->methodType() != QMetaMethod::Signal)
1082 if (signal->parameterCount() < method->parameterCount())
1084 const QMetaObject *smeta = signal->enclosingMetaObject();
1085 const QMetaObject *rmeta = method->enclosingMetaObject();
1086 for (
int i = 0; i < method->parameterCount(); ++i) {
1087 uint sourceTypeInfo = signal->parameterTypeInfo(i);
1088 uint targetTypeInfo = method->parameterTypeInfo(i);
1089 if ((sourceTypeInfo & IsUnresolvedType)
1090 || (targetTypeInfo & IsUnresolvedType)) {
1091 QByteArrayView sourceName = typeNameFromTypeInfo(smeta, sourceTypeInfo);
1092 QByteArrayView targetName = typeNameFromTypeInfo(rmeta, targetTypeInfo);
1093 if (sourceName != targetName)
1098 if (sourceType != targetType)
1110 if (self->d.relatedMetaObjects) {
1111 Q_ASSERT(priv(self->d.data)->revision >= 2);
1112 const auto *e = self->d.relatedMetaObjects;
1115 if (
const QMetaObject *m =QMetaObject_findMetaObject((*e), name))
1121 self = self->d.superdata;
1127
1128
1129
1130
1131
1132int QMetaObject::indexOfEnumerator(
const char *name)
const
1134 return QMetaObjectPrivate::indexOfEnumerator(
this, name);
1140 for (
auto which : { W::Name, W::Alias }) {
1141 if (
int index = indexOfEnumerator(m, name, which); index != -1)
1152 const QMetaEnum e(m, i);
1153 const quint32 id = which ==
Which::Name ? e.data.name() : e.data.alias();
1154 QByteArrayView prop = stringDataView(m, id);
1156 i += m->enumeratorOffset();
1166
1167
1168
1169
1170
1171int QMetaObject::indexOfProperty(
const char *name)
const
1173 const QMetaObject *m =
this;
1175 const QMetaObjectPrivate *d = priv(m->d.data);
1176 for (
int i = 0; i < d->propertyCount; ++i) {
1177 const QMetaProperty::Data data = QMetaProperty::getMetaPropertyData(m, i);
1178 const char *prop = rawStringData(m, data.name());
1179 if (strcmp(name, prop) == 0) {
1180 i += m->propertyOffset();
1187 if (priv(
this->d.data)->flags & DynamicMetaObject) {
1188 QAbstractDynamicMetaObject *me =
1189 const_cast<QAbstractDynamicMetaObject *>(
static_cast<
const QAbstractDynamicMetaObject *>(
this));
1191 return me->createProperty(name,
nullptr);
1198
1199
1200
1201
1202
1203int QMetaObject::indexOfClassInfo(
const char *name)
const
1206 const QMetaObject *m =
this;
1207 while (m && i < 0) {
1208 for (i = priv(m->d.data)->classInfoCount-1; i >= 0; --i)
1209 if (strcmp(name, rawStringData(m, m->d.data[priv(m->d.data)->classInfoData + 2*i])) == 0) {
1210 i += m->classInfoOffset();
1219
1220
1221
1222
1223
1224
1225QMetaMethod QMetaObject::constructor(
int index)
const
1228 if (i >= 0 && i < priv(d.data)->constructorCount)
1229 return QMetaMethod::fromRelativeConstructorIndex(
this, i);
1230 return QMetaMethod();
1234
1235
1236
1237
1238QMetaMethod QMetaObject::method(
int index)
const
1241 i -= methodOffset();
1242 if (i < 0 && d.superdata)
1243 return d.superdata->method(index);
1245 if (i >= 0 && i < priv(d.data)->methodCount)
1246 return QMetaMethod::fromRelativeMethodIndex(
this, i);
1247 return QMetaMethod();
1251
1252
1253
1254
1255QMetaEnum QMetaObject::enumerator(
int index)
const
1258 i -= enumeratorOffset();
1259 if (i < 0 && d.superdata)
1260 return d.superdata->enumerator(index);
1262 if (i >= 0 && i < priv(d.data)->enumeratorCount)
1263 return QMetaEnum(
this, i);
1268
1269
1270
1271
1272
1273QMetaProperty QMetaObject::property(
int index)
const
1276 i -= propertyOffset();
1277 if (i < 0 && d.superdata)
1278 return d.superdata->property(index);
1280 if (i >= 0 && i < priv(d.data)->propertyCount)
1281 return QMetaProperty(
this, i);
1282 return QMetaProperty();
1286
1287
1288
1289
1290
1291
1292QMetaProperty QMetaObject::userProperty()
const
1294 const int propCount = propertyCount();
1295 for (
int i = propCount - 1; i >= 0; --i) {
1296 const QMetaProperty prop = property(i);
1300 return QMetaProperty();
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313QMetaClassInfo QMetaObject::classInfo(
int index)
const
1316 i -= classInfoOffset();
1317 if (i < 0 && d.superdata)
1318 return d.superdata->classInfo(index);
1320 QMetaClassInfo result;
1321 if (i >= 0 && i < priv(d.data)->classInfoCount) {
1323 result.data = { d.data + priv(d.data)->classInfoData + i * QMetaClassInfo::Data::Size };
1329
1330
1331
1332
1333
1334
1335
1336bool QMetaObject::checkConnectArgs(
const char *signal,
const char *method)
1338 const char *s1 = signal;
1339 const char *s2 = method;
1340 while (*s1++ !=
'(') { }
1341 while (*s2++ !=
'(') { }
1342 if (*s2 ==
')' || qstrcmp(s1,s2) == 0)
1344 const auto s1len = qstrlen(s1);
1345 const auto s2len = qstrlen(s2);
1346 if (s2len < s1len && strncmp(s1,s2,s2len-1)==0 && s1[s2len-1]==
',')
1352
1353
1354
1355
1356
1357
1358bool QMetaObject::checkConnectArgs(
const QMetaMethod &signal,
1359 const QMetaMethod &method)
1361 return QMetaObjectPrivate::checkConnectArgs(
1362 QMetaMethodPrivate::get(&signal),
1363 QMetaMethodPrivate::get(&method));
1368 return std::find_if_not(in.begin(), in.end(), is_space);
1373 auto rit = std::find_if_not(in.rbegin(), in.rend(), is_space);
1374 in = in.first(rit.base() - in.begin());
1380 const char *d = in.begin();
1382 const char *end = in.end();
1386 while (d != end && (templdepth
1387 || (*d !=
',' && *d !=
')'))) {
1396 auto type = QByteArrayView{t, d - t};
1397 type = trimSpacesFromRight(type);
1398 if (type ==
"void") {
1399 const char *next = trimSpacesFromLeft(QByteArrayView{d, end});
1400 if (next != end && *next ==
')')
1404 normalizeTypeInternal(QByteArrayView{t, d}, result);
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424QByteArray QMetaObject::normalizedType(
const char *type)
1426 return normalizeTypeInternal(type, type + qstrlen(type));
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1444 method = trimSpacesFromRight(method);
1445 if (method.isEmpty())
1448 const char *d = method.begin();
1449 const char *end = method.end();
1450 d = trimSpacesFromLeft({d, end});
1453 result.reserve(method.size());
1459 Q_ASSERT(!result.isEmpty());
1461 d = trimSpacesFromLeft({d, end});
1472 if (argdepth == 1) {
1473 d = qNormalizeType(QByteArrayView{d, end}, templdepth, result);
1487QByteArray QMetaObject::normalizedSignature(
const char *method)
1489 return QMetaObjectPrivate::normalizedSignature(method);
1494 const char *
const *names,
1499 for (
int i = 0; i < meta->methodCount(); ++i) {
1500 const QMetaMethod method = meta->method(i);
1501 if (method.name() == name)
1502 candidateMessage +=
" " + method.methodSignature() +
'\n';
1504 if (!candidateMessage.isEmpty()) {
1505 candidateMessage.prepend(
"\nCandidates are:\n");
1506 candidateMessage.chop(1);
1509 QVarLengthArray<
char, 512> sig;
1510 for (qsizetype i = 1; i < paramCount; ++i) {
1512 sig.append(names[i], qstrlen(names[i]));
1514 sig.append(metaTypes[i]->name, qstrlen(metaTypes[i]->name));
1517 if (paramCount != 1)
1518 sig.resize(sig.size() - 1);
1520 qWarning(
"QMetaObject::invokeMethod: No such method %s::%.*s(%.*s)%.*s",
1521 meta->className(),
int(name.size()), name.constData(),
1522 int(sig.size()), sig.constData(),
1523 int(candidateMessage.size()), candidateMessage.constData());
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642bool QMetaObject::invokeMethod(QObject *obj,
1644 Qt::ConnectionType type,
1645 QGenericReturnArgument ret,
1646 QGenericArgument val0,
1647 QGenericArgument val1,
1648 QGenericArgument val2,
1649 QGenericArgument val3,
1650 QGenericArgument val4,
1651 QGenericArgument val5,
1652 QGenericArgument val6,
1653 QGenericArgument val7,
1654 QGenericArgument val8,
1655 QGenericArgument val9)
1660 const char *typeNames[] = {ret.name(), val0.name(), val1.name(), val2.name(), val3.name(),
1661 val4.name(), val5.name(), val6.name(), val7.name(), val8.name(),
1663 const void *parameters[] = {ret.data(), val0.data(), val1.data(), val2.data(), val3.data(),
1664 val4.data(), val5.data(), val6.data(), val7.data(), val8.data(),
1667 for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
1668 if (qstrlen(typeNames[paramCount]) <= 0)
1671 return invokeMethodImpl(obj, member, type, paramCount, parameters, typeNames,
nullptr);
1674bool QMetaObject::invokeMethodImpl(QObject *obj,
const char *member, Qt::ConnectionType type,
1675 qsizetype paramCount,
const void *
const *parameters,
1676 const char *
const *typeNames,
1677 const QtPrivate::QMetaTypeInterface *
const *metaTypes)
1682 Q_ASSERT(paramCount >= 1);
1683 Q_ASSERT(parameters);
1684 Q_ASSERT(typeNames);
1687 QByteArrayView name(member);
1691 const QMetaObject *meta = obj->metaObject();
1692 for ( ; meta; meta = meta->superClass()) {
1693 auto priv = QMetaObjectPrivate::get(meta);
1694 for (
int i = 0; i < priv->methodCount; ++i) {
1695 QMetaMethod m = QMetaMethod::fromRelativeMethodIndex(meta, i);
1696 if (m.parameterCount() != (paramCount - 1))
1698 if (name != stringDataView(meta, m.data.name()))
1702 QMetaMethodPrivate::InvokeFailReason r =
1703 QMetaMethodPrivate::invokeImpl(m, obj, type, paramCount, parameters,
1704 typeNames, metaTypes);
1706 return r == QMetaMethodPrivate::InvokeFailReason::None;
1711 return printMethodNotFoundWarning(obj->metaObject(), name, paramCount, typeNames, metaTypes);
1714bool QMetaObject::invokeMethodImpl(QObject *object, QtPrivate::QSlotObjectBase *slotObj, Qt::ConnectionType type,
1715 qsizetype parameterCount,
const void *
const *params,
const char *
const *names,
1716 const QtPrivate::QMetaTypeInterface *
const *metaTypes)
1721 auto slot = QtPrivate::SlotObjUniquePtr(slotObj);
1726 Qt::HANDLE currentThreadId = QThread::currentThreadId();
1727 QThread *objectThread = object->thread();
1728 bool receiverInSameThread =
false;
1730 receiverInSameThread = currentThreadId == QThreadData::get2(objectThread)->threadId.loadRelaxed();
1732 if (type == Qt::AutoConnection)
1733 type = receiverInSameThread ? Qt::DirectConnection : Qt::QueuedConnection;
1735 void **argv =
const_cast<
void **>(params);
1736 if (type == Qt::DirectConnection) {
1737 slot->call(object, argv);
1738 }
else if (type == Qt::QueuedConnection) {
1740 qWarning(
"QMetaObject::invokeMethod: Unable to invoke methods with return values in "
1741 "queued connections");
1744 QCoreApplication::postEvent(object,
new QQueuedMetaCallEvent(std::move(slot),
nullptr, -1,
1745 parameterCount, metaTypes, params));
1746 }
else if (type == Qt::BlockingQueuedConnection) {
1747#if QT_CONFIG(thread)
1748 if (receiverInSameThread)
1749 qWarning(
"QMetaObject::invokeMethod: Dead lock detected");
1752 QCoreApplication::postEvent(object,
new QMetaCallEvent(std::move(slot),
nullptr, -1, argv, &latch));
1756 qWarning(
"QMetaObject::invokeMethod: Unknown connection type");
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1864
1865
1866
1867
1869
1870
1871
1872
1873
1876
1877
1878
1879
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1900
1901
1902
1903
1904
1905
1906
1907
1910
1911
1912
1913
1914
1915
1918
1919
1920
1921
1922
1923
1926
1927
1928
1929
1930
1931
1934
1935
1936
1939
1940
1941
1942
1943
1944
1945
1948
1949
1950
1953
1954
1955QMetaMethod QMetaMethod::fromRelativeMethodIndex(
const QMetaObject *mobj,
int index)
1957 Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->methodCount);
1960 m.data = { mobj->d.data + priv(mobj->d.data)->methodData + index * Data::Size };
1964QMetaMethod QMetaMethod::fromRelativeConstructorIndex(
const QMetaObject *mobj,
int index)
1966 Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->constructorCount);
1969 m.data = { mobj->d.data + priv(mobj->d.data)->constructorData + index * Data::Size };
1974
1975
1976
1977
1978
1979
1983 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
1985 result.reserve(256);
1988 QList<QByteArray> argTypes = parameterTypes();
1989 for (
int i = 0; i < argTypes.size(); ++i) {
1992 result += argTypes.at(i);
1998QByteArrayView QMetaMethodPrivate::name()
const noexcept
2000 QByteArrayView name = qualifiedName();
2001 if (qsizetype colon = name.lastIndexOf(
':'); colon > 0)
2002 return name.sliced(colon + 1);
2006QByteArrayView QMetaMethodPrivate::qualifiedName()
const noexcept
2008 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2009 return stringDataView(mobj, data.name());
2012int QMetaMethodPrivate::typesDataIndex()
const
2014 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2015 return data.parameters();
2018const char *QMetaMethodPrivate::rawReturnTypeName()
const
2020 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2021 uint typeInfo = mobj->d.data[typesDataIndex()];
2022 if (typeInfo & IsUnresolvedType)
2023 return rawStringData(mobj, typeInfo & TypeNameIndexMask);
2025 return QMetaType(typeInfo).name();
2028int QMetaMethodPrivate::returnType()
const
2030 return parameterType(-1);
2033int QMetaMethodPrivate::parameterCount()
const
2035 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2043 uint typeInfo = parameterTypeInfo(index);
2046 if ((typeInfo & IsUnresolvedType) == 0)
2047 Q_ASSERT(mt.id() ==
int(typeInfo & TypeNameIndexMask));
2048 Q_ASSERT(mt.name());
2054#define ASSERT_NOT_PRIMITIVE_TYPE(TYPE, METATYPEID, NAME)
2055 Q_ASSERT(typeInfo != QMetaType::TYPE);
2057#undef ASSERT_NOT_PRIMITIVE_TYPE
2058 Q_ASSERT(typeInfo != QMetaType::QObjectStar);
2061 if (priv(mobj->d.data)->revision >= 11) {
2062 Q_ASSERT(typeInfo != QMetaType::Void);
2063 Q_ASSERT(typeInfo != QMetaType::VoidStar);
2068int QMetaMethodPrivate::parametersDataIndex()
const
2070 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2071 return typesDataIndex() + 1;
2074uint QMetaMethodPrivate::parameterTypeInfo(
int index)
const
2076 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2077 return mobj->d.data[parametersDataIndex() + index];
2082 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2083 if (methodType() == QMetaMethod::Constructor)
2087 checkMethodMetaTypeConsistency(iface, -1);
2093 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2094 int offset = (methodType() == QMetaMethod::Constructor ? 0 : 1);
2095 const auto ifaces = &mobj->d.metaTypes[data.metaTypeOffset() + offset];
2097 for (
int i = 0; i < parameterCount(); ++i)
2098 checkMethodMetaTypeConsistency(ifaces[i], i);
2103int QMetaMethodPrivate::parameterType(
int index)
const
2105 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2106 return typeFromTypeInfo(mobj, parameterTypeInfo(index));
2109void QMetaMethodPrivate::getParameterTypes(
int *types)
const
2111 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2112 int dataIndex = parametersDataIndex();
2113 int argc = parameterCount();
2114 for (
int i = 0; i < argc; ++i) {
2115 int id = typeFromTypeInfo(mobj, mobj->d.data[dataIndex++]);
2120QByteArrayView QMetaMethodPrivate::parameterTypeName(
int index)
const noexcept
2122 int paramsIndex = parametersDataIndex();
2123 return typeNameFromTypeInfo(mobj, mobj->d.data[paramsIndex + index]);
2126QList<QByteArray> QMetaMethodPrivate::parameterTypes()
const
2128 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2129 int argc = parameterCount();
2130 QList<QByteArray> list;
2132 int paramsIndex = parametersDataIndex();
2133 for (
int i = 0; i < argc; ++i) {
2134 QByteArrayView name = typeNameFromTypeInfo(mobj, mobj->d.data[paramsIndex + i]);
2135 list.emplace_back(name.toByteArray());
2140QList<QByteArray> QMetaMethodPrivate::parameterNames()
const
2142 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2143 int argc = parameterCount();
2144 QList<QByteArray> list;
2146 int namesIndex = parametersDataIndex() + argc;
2147 for (
int i = 0; i < argc; ++i)
2148 list += stringData(mobj, mobj->d.data[namesIndex + i]);
2152const char *QMetaMethodPrivate::tag()
const
2154 Q_ASSERT(priv(mobj->d.data)->revision >= 7);
2155 return rawStringData(mobj, data.tag());
2158int QMetaMethodPrivate::ownMethodIndex()
const
2161 return ( data.d - mobj->d.data - priv(mobj->d.data)->methodData)/Data::Size;
2164int QMetaMethodPrivate::ownConstructorMethodIndex()
const
2167 Q_ASSERT(methodType() == Constructor);
2168 return ( data.d - mobj->d.data - priv(mobj->d.data)->constructorData)/Data::Size;
2172
2173
2174
2175
2176
2177
2178
2179QByteArray QMetaMethod::methodSignature()
const
2182 return QByteArray();
2183 return QMetaMethodPrivate::get(
this)->signature();
2187
2188
2189
2190
2191
2192
2193QByteArray QMetaMethod::name()
const
2196 return QByteArray();
2198 return stringData(mobj, QMetaMethodPrivate::get(
this)->name());
2202
2203
2204
2205
2206
2207
2208
2209
2210QByteArrayView QMetaMethod::nameView()
const
2212 return QMetaMethodPrivate::get(
this)->name();
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225int QMetaMethod::returnType()
const
2227 return returnMetaType().id();
2231
2232
2233
2234
2235
2236QMetaType QMetaMethod::returnMetaType()
const
2238 if (!mobj || methodType() == QMetaMethod::Constructor)
2240 auto mt = QMetaType(mobj->d.metaTypes[data.metaTypeOffset()]);
2241 if (mt.id() == QMetaType::UnknownType)
2242 return QMetaType(QMetaMethodPrivate::get(
this)->returnType());
2248
2249
2250
2251
2252
2253
2254int QMetaMethod::parameterCount()
const
2258 return QMetaMethodPrivate::get(
this)->parameterCount();
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271int QMetaMethod::parameterType(
int index)
const
2273 return parameterMetaType(index).id();
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286QMetaType QMetaMethod::parameterMetaType(
int index)
const
2288 if (!mobj || index < 0)
2290 auto priv = QMetaMethodPrivate::get(
this);
2291 if (index >= priv->parameterCount())
2294 auto parameterOffset = index + (methodType() == QMetaMethod::Constructor ? 0 : 1);
2295 auto mt = QMetaType(mobj->d.metaTypes[data.metaTypeOffset() + parameterOffset]);
2296 if (mt.id() == QMetaType::UnknownType)
2297 return QMetaType(QMetaMethodPrivate::get(
this)->parameterType(index));
2303
2304
2305
2306
2307
2308
2309
2310
2311void QMetaMethod::getParameterTypes(
int *types)
const
2315 QMetaMethodPrivate::get(
this)->getParameterTypes(types);
2319
2320
2321
2322
2323QList<QByteArray> QMetaMethod::parameterTypes()
const
2326 return QList<QByteArray>();
2327 return QMetaMethodPrivate::get(
this)->parameterTypes();
2331
2332
2333
2334
2335
2336
2337QByteArray QMetaMethod::parameterTypeName(
int index)
const
2339 if (!mobj || index < 0 || index >= parameterCount())
2342 return stringData(mobj, QMetaMethodPrivate::get(
this)->parameterTypeName(index));
2346
2347
2348
2349
2350QList<QByteArray> QMetaMethod::parameterNames()
const
2353 return QList<QByteArray>();
2354 return QMetaMethodPrivate::get(
this)->parameterNames();
2359
2360
2361
2362
2363
2364
2365
2366
2367const char *QMetaMethod::typeName()
const
2371#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2372 if (methodType() == QMetaMethod::Constructor)
2375 return QMetaMethodPrivate::get(
this)->rawReturnTypeName();
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402const char *QMetaMethod::tag()
const
2406 return QMetaMethodPrivate::get(
this)->tag();
2411
2412
2413int QMetaMethod::attributes()
const
2417 return data.flags() >> 4;
2421
2422
2423
2424
2425int QMetaMethod::methodIndex()
const
2429 return QMetaMethodPrivate::get(
this)->ownMethodIndex() + mobj->methodOffset();
2433
2434
2435
2436
2437int QMetaMethod::relativeMethodIndex()
const
2441 return QMetaMethodPrivate::get(
this)->ownMethodIndex();
2446
2447
2448
2449
2450
2451int QMetaMethod::revision()
const
2455 if ((data.flags() & MethodRevisioned) == 0)
2457#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
2458 if (priv(mobj->d.data)->revision < 13) {
2460 int offset = priv(mobj->d.data)->methodData
2461 + priv(mobj->d.data)->methodCount * Data::Size
2462 + QMetaMethodPrivate::get(
this)->ownMethodIndex();
2463 return mobj->d.data[offset];
2467 return mobj->d.data[data.parameters() - 1];
2471
2472
2473
2474
2475
2476
2477
2478bool QMetaMethod::isConst()
const
2482 if (QMetaObjectPrivate::get(mobj)->revision < 10)
2484 return data.flags() & MethodIsConst;
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497QMetaMethod::Access QMetaMethod::access()
const
2499 constexpr int AccessShift = qCountTrailingZeroBits(AccessMask);
2500 static_assert(AccessPrivate >> AccessShift == Private);
2501 static_assert(AccessProtected >> AccessShift == Protected);
2502 static_assert(AccessPublic >> AccessShift == Public);
2505 return Access((data.flags() & AccessMask) >> AccessShift);
2509
2510
2511
2512
2513QMetaMethod::MethodType QMetaMethod::methodType()
const
2515 constexpr int MethodShift = qCountTrailingZeroBits(MethodTypeMask);
2516 static_assert(MethodMethod >> MethodShift == Method);
2517 static_assert(MethodSignal >> MethodShift == Signal);
2518 static_assert(MethodSlot >> MethodShift == Slot);
2519 static_assert(MethodConstructor >> MethodShift == Constructor);
2521 return QMetaMethod::Method;
2522 return MethodType((data.flags() & MethodTypeMask) >> MethodShift);
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2538
2539
2540
2541
2542
2543
2544
2545QMetaMethod QMetaMethod::fromSignalImpl(
const QMetaObject *metaObject,
void **signal)
2548 void *args[] = { &i, signal };
2549 for (
const QMetaObject *m = metaObject; m; m = m->d.superdata) {
2550 m->static_metacall(QMetaObject::IndexOfMethod, 0, args);
2552 return QMetaMethod::fromRelativeMethodIndex(m, i);
2554 return QMetaMethod();
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669bool QMetaMethod::invoke(QObject *object,
2670 Qt::ConnectionType connectionType,
2671 QGenericReturnArgument returnValue,
2672 QGenericArgument val0,
2673 QGenericArgument val1,
2674 QGenericArgument val2,
2675 QGenericArgument val3,
2676 QGenericArgument val4,
2677 QGenericArgument val5,
2678 QGenericArgument val6,
2679 QGenericArgument val7,
2680 QGenericArgument val8,
2681 QGenericArgument val9)
const
2683 if (!object || !mobj)
2687 const char *typeNames[] = {
2715 for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
2716 if (qstrlen(typeNames[paramCount]) <= 0)
2719 return invokeImpl(*
this, object, connectionType, paramCount, param, typeNames,
nullptr);
2722bool QMetaMethod::invokeImpl(QMetaMethod self,
void *target, Qt::ConnectionType connectionType,
2723 qsizetype paramCount,
const void *
const *parameters,
2724 const char *
const *typeNames,
2725 const QtPrivate::QMetaTypeInterface *
const *metaTypes)
2727 if (!target || !self.mobj)
2729 QMetaMethodPrivate::InvokeFailReason r =
2730 QMetaMethodPrivate::invokeImpl(self, target, connectionType, paramCount, parameters,
2731 typeNames, metaTypes);
2732 if (Q_LIKELY(r == QMetaMethodPrivate::InvokeFailReason::None))
2735 if (
int(r) >=
int(QMetaMethodPrivate::InvokeFailReason::FormalParameterMismatch)) {
2736 int n =
int(r) -
int(QMetaMethodPrivate::InvokeFailReason::FormalParameterMismatch);
2737 qWarning(
"QMetaMethod::invoke: cannot convert formal parameter %d from %s in call to %s::%s",
2738 n, typeNames[n + 1] ? typeNames[n + 1] : metaTypes[n + 1]->name,
2739 self.mobj->className(), self.methodSignature().constData());
2741 if (r == QMetaMethodPrivate::InvokeFailReason::TooFewArguments) {
2742 qWarning(
"QMetaMethod::invoke: too few arguments (%d) in call to %s::%s",
2743 int(paramCount), self.mobj->className(), self.methodSignature().constData());
2749 Qt::ConnectionType connectionType,
2750 qsizetype paramCount,
const void *
const *parameters,
2751 const char *
const *typeNames,
2754 auto object =
static_cast<QObject *>(target);
2755 auto priv = QMetaMethodPrivate::get(&self);
2756 constexpr bool MetaTypesAreOptional = QT_VERSION < QT_VERSION_CHECK(7, 0, 0);
2757 auto methodMetaTypes = priv->parameterMetaTypeInterfaces();
2758 auto param =
const_cast<
void **>(parameters);
2760 Q_ASSERT(priv->mobj);
2761 Q_ASSERT(self.methodType() == Constructor || object);
2762 Q_ASSERT(self.methodType() == Constructor || connectionType == Qt::ConnectionType(-1) ||
2763 priv->mobj->cast(object));
2764 Q_ASSERT(paramCount >= 1);
2765 Q_ASSERT(parameters);
2766 Q_ASSERT(typeNames);
2767 Q_ASSERT(MetaTypesAreOptional || metaTypes);
2769 if ((paramCount - 1) < qsizetype(priv->data.argc()))
2773 auto checkTypesAreCompatible = [=](
int idx) {
2774 uint typeInfo = priv->parameterTypeInfo(idx - 1);
2775 QByteArrayView userTypeName(typeNames[idx] ? typeNames[idx] : metaTypes[idx]
->name);
2777 if ((typeInfo & IsUnresolvedType) == 0) {
2779 if (MetaTypesAreOptional && !metaTypes)
2780 return int(typeInfo) == QMetaType::fromName(userTypeName).id();
2781 return int(typeInfo) == metaTypes[idx]->typeId;
2784 QByteArrayView methodTypeName = stringDataView(priv->mobj, typeInfo & TypeNameIndexMask);
2785 if ((MetaTypesAreOptional && !metaTypes) || !metaTypes[idx]) {
2787 if (methodTypeName == userTypeName)
2791 QByteArray normalized = normalizeTypeInternal(userTypeName.begin(), userTypeName.end());
2792 return methodTypeName == normalized;
2796 Q_ASSERT(userType.isValid());
2797 if (QMetaType(methodMetaTypes[idx - 1]) == userType)
2802 if (methodMetaTypes[idx - 1])
2806 QMetaType resolved = QMetaType::fromName(methodTypeName);
2807 return resolved == userType;
2811 for (qsizetype i = 0; metaTypes && i < paramCount; ++i)
2815 for (qsizetype i = 1; i < paramCount; ++i) {
2816 if (!checkTypesAreCompatible(i))
2821 if (self.methodType() == Constructor) {
2823 qWarning(
"QMetaMethod::invokeMethod: cannot call constructor %s on object %p",
2824 self.methodSignature().constData(), object);
2828 if (!parameters[0]) {
2829 qWarning(
"QMetaMethod::invokeMethod: constructor call to %s must assign a return type",
2830 self.methodSignature().constData());
2834 if (!MetaTypesAreOptional || metaTypes) {
2835 if (metaTypes[0]->typeId != QMetaType::QObjectStar) {
2836 qWarning(
"QMetaMethod::invokeMethod: cannot convert QObject* to %s on constructor call %s",
2837 metaTypes[0]
->name, self.methodSignature().constData());
2842 int idx = priv->ownConstructorMethodIndex();
2843 if (priv->mobj->static_metacall(QMetaObject::CreateInstance, idx, param) >= 0)
2849 if (parameters[0]) {
2850 if (!checkTypesAreCompatible(0)) {
2851 const char *retType = typeNames[0] ? typeNames[0] : metaTypes[0]
->name;
2852 qWarning(
"QMetaMethod::invokeMethod: return type mismatch for method %s::%s:"
2853 " cannot convert from %s to %s during invocation",
2854 priv->mobj->className(), priv->methodSignature().constData(),
2855 priv->rawReturnTypeName(), retType);
2860 Qt::HANDLE currentThreadId =
nullptr;
2861 QThread *objectThread =
nullptr;
2862 auto receiverInSameThread = [&]() {
2863 if (!currentThreadId) {
2864 currentThreadId = QThread::currentThreadId();
2865 objectThread = object->thread();
2868 return currentThreadId == QThreadData::get2(objectThread)->threadId.loadRelaxed();
2873 if (connectionType == Qt::AutoConnection)
2874 connectionType = receiverInSameThread() ? Qt::DirectConnection : Qt::QueuedConnection;
2875 else if (connectionType == Qt::ConnectionType(-1))
2876 connectionType = Qt::DirectConnection;
2878#if !QT_CONFIG(thread)
2879 if (connectionType == Qt::BlockingQueuedConnection) {
2880 connectionType = Qt::DirectConnection;
2885 int idx_relative = priv->ownMethodIndex();
2886 int idx_offset = priv->mobj->methodOffset();
2887 QObjectPrivate::StaticMetaCallFunction callFunction = priv->mobj->d.static_metacall;
2889 if (connectionType == Qt::DirectConnection) {
2891 callFunction(object, QMetaObject::InvokeMetaMethod, idx_relative, param);
2892 else if (QMetaObject::metacall(object, QMetaObject::InvokeMetaMethod, idx_relative + idx_offset, param) >= 0)
2894 }
else if (connectionType == Qt::QueuedConnection) {
2895 if (parameters[0]) {
2896 qWarning(
"QMetaMethod::invoke: Unable to invoke methods with return values in "
2897 "queued connections");
2901 QVarLengthArray<
const QtPrivate::QMetaTypeInterface *, 16> argTypes;
2902 argTypes.reserve(paramCount);
2903 argTypes.emplace_back(
nullptr);
2905 for (
int i = 1; i < paramCount; ++i) {
2906 QMetaType type = QMetaType(methodMetaTypes[i - 1]);
2907 if (!type.iface() && (!MetaTypesAreOptional || metaTypes))
2908 type = QMetaType(metaTypes[i]);
2910 type = priv->parameterMetaType(i - 1);
2911 if (!type.iface() && typeNames[i])
2912 type = QMetaType::fromName(typeNames[i]);
2913 if (!type.iface()) {
2914 qWarning(
"QMetaMethod::invoke: Unable to handle unregistered datatype '%s'",
2918 argTypes.emplace_back(type.iface());
2921 QCoreApplication::postEvent(object,
new QQueuedMetaCallEvent(idx_offset, idx_relative, callFunction,
nullptr,
2922 -1, paramCount, argTypes.data(), parameters));
2924#if QT_CONFIG(thread)
2925 if (receiverInSameThread()) {
2926 qWarning(
"QMetaMethod::invoke: Dead lock detected in BlockingQueuedConnection: "
2927 "Receiver is %s(%p)", priv->mobj->className(), object);
2928 return InvokeFailReason::DeadLockDetected;
2932 QCoreApplication::postEvent(object,
new QMetaCallEvent(idx_offset, idx_relative, callFunction,
2933 nullptr, -1, param, &latch));
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043bool QMetaMethod::invokeOnGadget(
void *gadget,
3044 QGenericReturnArgument returnValue,
3045 QGenericArgument val0,
3046 QGenericArgument val1,
3047 QGenericArgument val2,
3048 QGenericArgument val3,
3049 QGenericArgument val4,
3050 QGenericArgument val5,
3051 QGenericArgument val6,
3052 QGenericArgument val7,
3053 QGenericArgument val8,
3054 QGenericArgument val9)
const
3056 if (!gadget || !mobj)
3060 if (returnValue.data()) {
3061 const char *retType = typeName();
3062 if (qstrcmp(returnValue.name(), retType) != 0) {
3064 QByteArray normalized = QMetaObject::normalizedType(returnValue.name());
3065 if (qstrcmp(normalized.constData(), retType) != 0) {
3067 int t = returnType();
3068 if (t == QMetaType::UnknownType || t != QMetaType::fromName(normalized).id())
3075 const char *typeNames[] = {
3089 for (paramCount = 1; paramCount < MaximumParamCount; ++paramCount) {
3090 if (qstrlen(typeNames[paramCount]) <= 0)
3093 if (paramCount <= QMetaMethodPrivate::get(
this)->parameterCount())
3110 int idx_relative = QMetaMethodPrivate::get(
this)->ownMethodIndex();
3111 Q_ASSERT(QMetaObjectPrivate::get(mobj)->revision >= 6);
3112 QObjectPrivate::StaticMetaCallFunction callFunction = mobj->d.static_metacall;
3115 callFunction(
reinterpret_cast<QObject*>(gadget), QMetaObject::InvokeMetaMethod, idx_relative, param);
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3176
3177
3178
3179
3180
3181
3182
3185
3186
3187
3191
3192
3193
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206const char *QMetaEnum::name()
const
3210 return rawStringData(mobj, data.name());
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225const char *QMetaEnum::enumName()
const
3229 return rawStringData(mobj, data.alias());
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244QMetaType QMetaEnum::metaType()
const
3249 const QMetaObjectPrivate *p = priv(mobj->d.data);
3250#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
)
3251 if (p->revision < 12)
3255 return QMetaType(mobj->d.metaTypes[data.index(mobj) + p->propertyCount]);
3259
3260
3261
3262
3263int QMetaEnum::keyCount()
const
3267 return data.keyCount();
3271
3272
3273
3274
3275const char *QMetaEnum::key(
int index)
const
3279 if (index >= 0 && index <
int(data.keyCount()))
3280 return rawStringData(mobj, mobj->d.data[data.data() + 2*index]);
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294int QMetaEnum::value(
int index)
const
3296 return value64(index).value_or(-1);
3304Q_DECL_PURE_FUNCTION
static inline EnumExtendMode enumExtendMode(
const QMetaEnum &e)
3310 if (e.metaType().flags() & QMetaType::IsUnsignedEnumeration)
3322 return value == uint(value);
3323 return value == quint64(
int(value));
3326template <
typename... Mode>
inline
3327quint64 QMetaEnum::value_helper(uint index, Mode... modes)
const noexcept
3329 static_assert(
sizeof...(Mode) < 2);
3330 if constexpr (
sizeof...(Mode) == 0) {
3331 return value_helper(index, enumExtendMode(*
this));
3332 }
else if constexpr (
sizeof...(Mode) == 1) {
3333 auto mode = (modes, ...);
3334 quint64 value = mobj->d.data[data.data() + 2U * index + 1];
3336 value |= quint64(mobj->d.data[data.data() + 2U * data.keyCount() + index]) << 32;
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365std::optional<quint64> QMetaEnum::value64(
int index)
const
3368 return std::nullopt;
3369 if (index < 0 || index >=
int(data.keyCount()))
3370 return std::nullopt;
3372 return value_helper(index);
3376
3377
3378
3379
3380
3381
3382
3383
3384bool QMetaEnum::isFlag()
const
3388 return data.flags() & EnumIsFlag;
3392
3393
3394
3395
3396
3397bool QMetaEnum::isScoped()
const
3401 return data.flags() & EnumIsScoped;
3405
3406
3407
3408
3409
3410
3411bool QMetaEnum::is64Bit()
const
3415 return data.flags() & EnumIs64Bit;
3419
3420
3421
3422
3423
3424
3425
3426const char *QMetaEnum::scope()
const
3428 return mobj ? mobj->className() :
nullptr;
3433 const QByteArrayView className = e->enclosingMetaObject()->className();
3438 if (scope == className)
3444 QByteArrayView name = e->enumName();
3448 const auto sz = className.size();
3449 if (scope.size() == sz + qsizetype(qstrlen(
"::")) + name.size()
3450 && scope.startsWith(className)
3451 && scope.sliced(sz, 2) ==
"::"
3452 && scope.sliced(sz + 2) == name)
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473int QMetaEnum::keyToValue(
const char *key,
bool *ok)
const
3475 auto value = keyToValue64(key);
3477 *ok = value.has_value();
3478 return int(value.value_or(-1));
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493std::optional<quint64> QMetaEnum::keyToValue64(
const char *key)
const
3496 return std::nullopt;
3497 const auto [scope, enumKey] = parse_scope(QLatin1StringView(key));
3498 for (
int i = 0; i <
int(data.keyCount()); ++i) {
3499 if ((!scope || isScopeMatch(*scope,
this))
3500 && enumKey == stringDataView(mobj, mobj->d.data[data.data() + 2 * i])) {
3501 return value_helper(i);
3504 return std::nullopt;
3508
3509
3510
3511
3512
3513
3514
3515const char *QMetaEnum::valueToKey(quint64 value)
const
3520 EnumExtendMode mode = enumExtendMode(*
this);
3521 if (!isEnumValueSuitable(value, mode))
3524 for (
int i = 0; i <
int(data.keyCount()); ++i) {
3525 if (value == value_helper(i, mode))
3526 return rawStringData(mobj, mobj->d.data[data.data() + 2 * i]);
3531static bool parseEnumFlags(QByteArrayView v, QVarLengthArray<QByteArrayView, 10> &list)
3535 qWarning(
"QMetaEnum::keysToValue: empty keys string.");
3539 qsizetype sep = v.indexOf(
'|', 0);
3541 qWarning(
"QMetaEnum::keysToValue: malformed keys string, starts with '|', \"%s\"",
3551 if (v.endsWith(
'|')) {
3552 qWarning(
"QMetaEnum::keysToValue: malformed keys string, ends with '|', \"%s\"",
3557 const auto begin = v.begin();
3558 const auto end = v.end();
3560 for (; b != end && sep != -1; sep = v.indexOf(
'|', sep)) {
3561 list.push_back({b, begin + sep});
3565 qWarning(
"QMetaEnum::keysToValue: malformed keys string, has two consecutive '|': "
3566 "\"%s\"", v.constData());
3572 list.push_back({b, end});
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590int QMetaEnum::keysToValue(
const char *keys,
bool *ok)
const
3592 auto value = keysToValue64(keys);
3594 *ok = value.has_value();
3595 return int(value.value_or(-1));
3599
3600
3601
3602
3603
3604
3605
3606
3607std::optional<quint64> QMetaEnum::keysToValue64(
const char *keys)
const
3610 return std::nullopt;
3612 EnumExtendMode mode = enumExtendMode(*
this);
3613 auto lookup = [&] (QByteArrayView key) -> std::optional<quint64> {
3614 for (
int i = data.keyCount() - 1; i >= 0; --i) {
3615 if (key == stringDataView(mobj, mobj->d.data[data.data() + 2*i]))
3616 return value_helper(i, mode);
3618 return std::nullopt;
3622 QVarLengthArray<QByteArrayView, 10> list;
3623 const bool r = parseEnumFlags(QByteArrayView{keys}, list);
3625 return std::nullopt;
3626 for (
const auto &untrimmed : list) {
3627 const auto parsed = parse_scope(untrimmed.trimmed());
3628 if (parsed.scope && !isScopeMatch(*parsed.scope,
this))
3629 return std::nullopt;
3630 if (
auto thisValue = lookup(parsed.key))
3631 value |= *thisValue;
3633 return std::nullopt;
3640template <
typename String,
typename Container,
typename Separator>
3641void join_reversed(String &s,
const Container &c, Separator sep)
3645 qsizetype len = qsizetype(c.size()) - 1;
3647 len += qsizetype(e.size());
3650 for (
auto rit = c.rbegin(), rend = c.rend(); rit != rend; ++rit) {
3651 const auto &e = *rit;
3655 s.append(e.data(), e.size());
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670QByteArray QMetaEnum::valueToKeys(quint64 value)
const
3676 EnumExtendMode mode = enumExtendMode(*
this);
3677 if (!isEnumValueSuitable(value, mode))
3680 QVarLengthArray<QByteArrayView,
sizeof(
int) * CHAR_BIT> parts;
3684 for (
int i = data.keyCount() - 1; i >= 0; --i) {
3685 quint64 k = value_helper(i, mode);
3686 if ((k != 0 && (v & k) == k) || (k == value)) {
3688 parts.push_back(stringDataView(mobj, mobj->d.data[data.data() + 2 * i]));
3691 join_reversed(keys, parts,
'|');
3696
3697
3698QMetaEnum::QMetaEnum(
const QMetaObject *mobj,
int index)
3699 : mobj(mobj), data({ mobj->d.data + priv(mobj->d.data)->enumeratorData + index * Data::Size })
3701 Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->enumeratorCount);
3704int QMetaEnum::Data::index(
const QMetaObject *mobj)
const
3706#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
3707# warning "Consider changing Size to a power of 2"
3709 return (
unsigned(d - mobj->d.data) - priv(mobj->d.data)->enumeratorData) / Size;
3713
3714
3715
3716
3717
3718
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3757
3758
3759
3760
3761
3762
3763
3766
3767
3768
3771
3772
3773
3776
3777
3778
3779
3780const char *QMetaProperty::name()
const
3784 return rawStringData(mobj, data.name());
3788
3789
3790
3791
3792const char *QMetaProperty::typeName()
const
3797 if (
const auto mt = metaType(); mt.isValid())
3799 return typeNameFromTypeInfo(mobj, data.type()).constData();
3803
3804
3805
3806
3807
3808
3809
3812
3813
3814
3815
3816
3817
3818
3819
3820
3823
3824
3825
3826
3827
3828
3829
3832
3833
3834
3835
3836
3837
3838QMetaType QMetaProperty::metaType()
const
3842 return QMetaType(mobj->d.metaTypes[data.index(mobj)]);
3845int QMetaProperty::Data::index(
const QMetaObject *mobj)
const
3847#if QT_VERSION >= QT_VERSION_CHECK(7
, 0
, 0
)
3848# warning "Consider changing Size to a power of 2"
3850 return (
unsigned(d - mobj->d.data) - priv(mobj->d.data)->propertyData) / Size;
3854
3855
3856
3857
3858int QMetaProperty::propertyIndex()
const
3862 return data.index(mobj) + mobj->propertyOffset();
3866
3867
3868
3869
3870int QMetaProperty::relativePropertyIndex()
const
3874 return data.index(mobj);
3878
3879
3880
3881
3882
3883
3884
3885
3887bool QMetaProperty::isFlagType()
const
3889 return isEnumType() && menum.isFlag();
3893
3894
3895
3896
3897
3898bool QMetaProperty::isEnumType()
const
3902 return (data.flags() & EnumOrFlag) && menum.name();
3906
3907
3908
3909
3910
3911
3912
3913
3914bool QMetaProperty::hasStdCppSet()
const
3918 return (data.flags() & StdCppSet);
3922
3923
3924
3925
3926
3927
3928bool QMetaProperty::isAlias()
const
3932 return (data.flags() & Alias);
3935#if QT_DEPRECATED_SINCE(6
, 4
)
3937
3938
3939
3940
3941
3942
3943
3944int QMetaProperty::registerPropertyType()
const
3950QMetaProperty::QMetaProperty(
const QMetaObject *mobj,
int index)
3952 data(getMetaPropertyData(mobj, index))
3954 Q_ASSERT(index >= 0 && index < priv(mobj->d.data)->propertyCount);
3956 if (!(data.flags() & EnumOrFlag) || !metaType().flags().testFlag(QMetaType::IsEnumeration))
3958 QByteArrayView enum_name = typeNameFromTypeInfo(mobj, data.type());
3959 menum = mobj->enumerator(QMetaObjectPrivate::indexOfEnumerator(mobj, enum_name));
3960 if (menum.isValid())
3963 QByteArrayView scope_name;
3964 const auto parsed = parse_scope(enum_name);
3966 scope_name = *parsed.scope;
3967 enum_name = parsed.key;
3969 scope_name = objectClassName(mobj);
3972 const QMetaObject *scope =
nullptr;
3973 if (scope_name ==
"Qt")
3974 scope = &Qt::staticMetaObject;
3976 scope = QMetaObject_findMetaObject(mobj, QByteArrayView(scope_name));
3979 menum = scope->enumerator(QMetaObjectPrivate::indexOfEnumerator(scope, enum_name));
3983
3984
3985
3986QMetaProperty::Data QMetaProperty::getMetaPropertyData(
const QMetaObject *mobj,
int index)
3988 return { mobj->d.data + priv(mobj->d.data)->propertyData + index * Data::Size };
3992
3993
3994
3995
3996
3997QMetaEnum QMetaProperty::enumerator()
const
4003
4004
4005
4006
4007
4008QVariant QMetaProperty::read(
const QObject *object)
const
4010 if (!object || !mobj)
4020 void *argv[] = {
nullptr, &value, &status };
4021 QMetaType t(mobj->d.metaTypes[data.index(mobj)]);
4022 if (t == QMetaType::fromType<QVariant>()) {
4025 value = QVariant(t,
nullptr);
4026 argv[0] = value.data();
4028 if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall) {
4029 mobj->d.static_metacall(
const_cast<QObject*>(object), QMetaObject::ReadProperty, data.index(mobj), argv);
4031 QMetaObject::metacall(
const_cast<QObject*>(object), QMetaObject::ReadProperty,
4032 data.index(mobj) + mobj->propertyOffset(), argv);
4037 if (t != QMetaType::fromType<QVariant>() && argv[0] != value.data())
4039 return QVariant(t, argv[0]);
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057bool QMetaProperty::write(QObject *object,
const QVariant &value)
const
4059 if (!object || !isWritable())
4061 return write(object, QVariant(value));
4065
4066
4067
4068bool QMetaProperty::write(QObject *object, QVariant &&v)
const
4070 if (!object || !isWritable())
4072 QMetaType t(mobj->d.metaTypes[data.index(mobj)]);
4073 if (t != QMetaType::fromType<QVariant>() && t != v.metaType()) {
4074 if (isEnumType() && !t.metaObject() && v.metaType() == QMetaType::fromType<QString>()) {
4078 std::optional value = isFlagType() ? menum.keysToValue64(v.toByteArray())
4079 : menum.keyToValue64(v.toByteArray());
4081 v = QVariant(qlonglong(*value));
4088 return reset(object);
4089 v = QVariant(t,
nullptr);
4090 }
else if (!v.convert(t)) {
4103 void *argv[] = {
nullptr, &v, &status, &flags };
4104 if (t == QMetaType::fromType<QVariant>())
4108 if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall)
4109 mobj->d.static_metacall(object, QMetaObject::WriteProperty, data.index(mobj), argv);
4111 QMetaObject::metacall(object, QMetaObject::WriteProperty, data.index(mobj) + mobj->propertyOffset(), argv);
4117
4118
4119
4120
4121
4122
4123
4124bool QMetaProperty::reset(QObject *object)
const
4126 if (!object || !mobj || !isResettable())
4128 void *argv[] = {
nullptr };
4129 if (priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall)
4130 mobj->d.static_metacall(object, QMetaObject::ResetProperty, data.index(mobj), argv);
4132 QMetaObject::metacall(object, QMetaObject::ResetProperty, data.index(mobj) + mobj->propertyOffset(), argv);
4137
4138
4139
4140
4141
4142
4143
4144
4145QUntypedBindable QMetaProperty::bindable(QObject *object)
const
4147 QUntypedBindable bindable;
4148 void * argv[1] { &bindable };
4149 mobj->metacall(object, QMetaObject::BindableProperty, data.index(mobj) + mobj->propertyOffset(), argv);
4153
4154
4155
4156
4157
4158
4159
4160QVariant QMetaProperty::readOnGadget(
const void *gadget)
const
4162 Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
4163 return read(
reinterpret_cast<
const QObject*>(gadget));
4167
4168
4169
4170
4171
4172
4173
4174bool QMetaProperty::writeOnGadget(
void *gadget,
const QVariant &value)
const
4176 Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
4177 return write(
reinterpret_cast<QObject*>(gadget), value);
4181
4182
4183
4184bool QMetaProperty::writeOnGadget(
void *gadget, QVariant &&value)
const
4186 Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
4187 return write(
reinterpret_cast<QObject*>(gadget), std::move(value));
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200bool QMetaProperty::resetOnGadget(
void *gadget)
const
4202 Q_ASSERT(priv(mobj->d.data)->flags & PropertyAccessInStaticMetaCall && mobj->d.static_metacall);
4203 return reset(
reinterpret_cast<QObject*>(gadget));
4207
4208
4209
4210
4211
4212bool QMetaProperty::isResettable()
const
4216 return data.flags() & Resettable;
4220
4221
4222
4223
4224bool QMetaProperty::isReadable()
const
4228 return data.flags() & Readable;
4232
4233
4234
4235
4236
4237bool QMetaProperty::hasNotifySignal()
const
4241 return data.notifyIndex() != uint(-1);
4245
4246
4247
4248
4249
4250
4251
4252QMetaMethod QMetaProperty::notifySignal()
const
4254 int id = notifySignalIndex();
4256 return mobj->method(id);
4258 return QMetaMethod();
4262
4263
4264
4265
4266
4267
4268
4269int QMetaProperty::notifySignalIndex()
const
4271 if (!mobj || data.notifyIndex() == std::numeric_limits<uint>::max())
4273 uint methodIndex = data.notifyIndex();
4274 if (!(methodIndex & IsUnresolvedSignal))
4275 return methodIndex + mobj->methodOffset();
4276 methodIndex &= ~IsUnresolvedSignal;
4277 const QByteArrayView signalName = stringDataView(mobj, methodIndex);
4278 const QMetaObject *m = mobj;
4280 int idx = QMetaObjectPrivate::indexOfMethodRelative(&m, signalName, {}, QMetaMethod::Signal);
4282 return idx + m->methodOffset();
4284 QArgumentType argType[] = {metaType()};
4285 idx = QMetaObjectPrivate::indexOfMethodRelative(&m, signalName, argType, QMetaMethod::Signal);
4287 return idx + m->methodOffset();
4288 qWarning(
"QMetaProperty::notifySignal: cannot find the NOTIFY signal %s in class %s for property '%s'",
4289 signalName.constData(), mobj->className(), name());
4295
4296
4297
4298
4299
4300
4301int QMetaProperty::revision()
const
4305 return data.revision();
4309
4310
4311
4312
4313
4314bool QMetaProperty::isWritable()
const
4318 return data.flags() & Writable;
4322
4323
4324
4325
4326
4327bool QMetaProperty::isDesignable()
const
4331 return data.flags() & Designable;
4335
4336
4337
4338
4339
4340bool QMetaProperty::isScriptable()
const
4344 return data.flags() & Scriptable;
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357bool QMetaProperty::isStored()
const
4361 return data.flags() & Stored;
4365
4366
4367
4368
4369
4370
4371
4372bool QMetaProperty::isUser()
const
4376 return data.flags() & User;
4380
4381
4382
4383
4384
4385
4386bool QMetaProperty::isConstant()
const
4390 return data.flags() & Constant;
4394
4395
4396
4397
4398
4399
4400bool QMetaProperty::isFinal()
const
4404 return data.flags() & Final;
4408
4409
4410
4411
4412
4413
4414bool QMetaProperty::isRequired()
const
4418 return data.flags() & Required;
4422
4423
4424
4425
4426
4427
4428
4429
4430bool QMetaProperty::isBindable()
const
4434 return (data.flags() & Bindable);
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4462
4463
4464
4467
4468
4469
4472
4473
4474
4475
4476const char *QMetaClassInfo::name()
const
4480 return rawStringData(mobj, data.name());
4484
4485
4486
4487
4488const char *QMetaClassInfo::value()
const
4492 return rawStringData(mobj, data.value());
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4510
4511
4512
4513
4514
4515
4516
4517
4518
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4546
4547
4548
4549
4552
4553
4554
4555
4558
4559
4560
4561
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4577
4578
4579
4580
4581
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4597 Q_ASSERT(local_method_index < get(mobj)->methodCount);
4598 while (QMetaMethod::fromRelativeMethodIndex(mobj, local_method_index).data.flags() & MethodCloned) {
4599 Q_ASSERT(local_method_index > 0);
4600 --local_method_index;
4602 return local_method_index;
4606
4607
4608
4609
4610
4611
4612
4613
4616 QVarLengthArray<QByteArrayView, 10> &typeNames)
4618 const char *signature =
static_cast<
const char *>(memchr(sig.begin(),
'(', sig.size()));
4621 auto name = QByteArrayView{sig.begin(), signature};
4623 if (!sig.endsWith(
')'))
4625 const char *end = sig.end() - 1;
4626 while (signature != end) {
4627 if (*signature ==
',')
4629 const char *begin = signature;
4631 while (signature != end && (level > 0 || *signature !=
',')) {
4632 if (*signature ==
'<')
4634 else if (*signature ==
'>')
4638 typeNames.append(QByteArrayView{begin, signature - begin});