19#if QT_CONFIG(easingcurve)
20#include "qeasingcurve.h"
24#if QT_CONFIG(regularexpression)
25# include "qregularexpression.h"
28#ifndef QT_BOOTSTRAPPED
48#if QT_CONFIG(itemmodel)
49# include "qabstractitemmodel.h"
52#ifndef QT_NO_GEOM_VARIANT
64#define NS(x) QT_PREPEND_NAMESPACE(x)
71struct QMetaTypeDeleter
74 void operator()(
void *data)
76 if (iface->alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__) {
77 operator
delete(data,
std::align_val_t(iface->alignment));
79 operator
delete(data);
84struct QMetaTypeCustomRegistry
87#if QT_VERSION < QT_VERSION_CHECK(7
, 0
, 0
) && !defined(QT_BOOTSTRAPPED)
88 QMetaTypeCustomRegistry()
91
92
93
94
95
96 aliases.insert(
"qfloat16", QtPrivate::qMetaTypeInterfaceForType<qfloat16>());
112 QWriteLocker l(&lock);
113 if (
int id = ti->typeId.loadRelaxed())
117 QMetaObject::normalizedType
120 if (
auto ti2 = aliases.value(name)) {
121 const auto id = ti2->typeId.loadRelaxed();
122 ti->typeId.storeRelaxed(id);
126 int size = registry.size();
127 while (firstEmpty < size && registry[firstEmpty])
129 if (firstEmpty < size) {
130 registry[firstEmpty] = ti;
134 firstEmpty = registry.size();
136 ti->typeId.storeRelaxed(firstEmpty + QMetaType::User);
140 return ti->typeId.loadRelaxed();
143 void unregisterDynamicType(
int id)
147 Q_ASSERT(id > QMetaType::User);
148 QWriteLocker l(&lock);
149 int idx = id - QMetaType::User - 1;
150 auto &ti = registry[idx];
153 aliases.removeIf([ti] (
const auto &kv) {
return kv.value() == ti; });
157 firstEmpty =
std::min(firstEmpty, idx);
162 QReadLocker l(&lock);
163 return registry.value(id - QMetaType::User - 1);
167Q_GLOBAL_STATIC(QMetaTypeCustomRegistry, customTypeRegistry)
173const char *QtMetaTypePrivate::typedefNameForType(
const QtPrivate::QMetaTypeInterface *type_d)
175 const char *name =
nullptr;
176 if (!customTypeRegistry.exists())
178 QMetaTypeCustomRegistry *r = &*customTypeRegistry;
180 QByteArrayView officialName(type_d->name);
181 QReadLocker l(&r->lock);
182 auto it = r->aliases.constBegin();
183 auto end = r->aliases.constEnd();
184 for ( ; it != end; ++it) {
185 if (it.value() != type_d)
187 if (it.key() == officialName)
189 name = it.key().constData();
195 QByteArrayList otherNames;
196 for ( ; it != end; ++it) {
197 if (it.value() == type_d && it.key() != officialName)
198 otherNames << it.key();
201 if (!otherNames.isEmpty())
202 qWarning(
"QMetaType: type %s has more than one typedef alias: %s, %s",
203 type_d->name, name, otherNames.join(
", ").constData());
210
211
212
213
214
215
216
217
218
219
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
320
321
322
323
324
325
326
327
328
329
330
331
332
333
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
507
508
509
510
511
512
513
514
517
518
519
520
521
522
523
524
525
528
529
530
531
532
535
536
537
538
539
540
541
542
544
545
546
547int QMetaType::registerHelper(
const QtPrivate::QMetaTypeInterface *iface)
550 auto reg = customTypeRegistry();
552 return reg->registerCustomType(iface);
558
559
560
561
562
563
564
565
566
567
568
569
572
573
574
575
576
577
578
579
580
581
582
583
584
587
588
589
590
591
592
593
594
595
596
597
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
623
624
625
626
627
628
629
630
631
632void *QMetaType::create(
const void *copy)
const
634 if (copy ? !isCopyConstructible() : !isDefaultConstructible())
637 std::unique_ptr<
void, QMetaTypeDeleter> where(
nullptr, {d_ptr});
638 if (d_ptr->alignment > __STDCPP_DEFAULT_NEW_ALIGNMENT__)
639 where.reset(operator
new(d_ptr->size, std::align_val_t(d_ptr->alignment)));
641 where.reset(operator
new(d_ptr->size));
643 QtMetaTypePrivate::construct(d_ptr, where.get(), copy);
644 return where.release();
648
649
650
651
652
653
654
655
656void QMetaType::destroy(
void *data)
const
658 if (data && isDestructible()) {
659 QtMetaTypePrivate::destruct(d_ptr, data);
660 QMetaTypeDeleter{d_ptr}(data);
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690void *QMetaType::construct(
void *where,
const void *copy)
const
694 if (copy ? !isCopyConstructible() : !isDefaultConstructible())
697 QtMetaTypePrivate::construct(d_ptr, where, copy);
702
703
704
705
706
707
708
709
710
711
712void QMetaType::destruct(
void *data)
const
714 if (data && isDestructible())
715 QtMetaTypePrivate::destruct(d_ptr, data);
718static QPartialOrdering threeWayCompare(
const void *ptr1,
const void *ptr2)
720 std::less<
const void *> less;
721 if (less(ptr1, ptr2))
722 return QPartialOrdering::Less;
723 if (less(ptr2, ptr1))
724 return QPartialOrdering::Greater;
725 return QPartialOrdering::Equivalent;
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754QPartialOrdering QMetaType::compare(
const void *lhs,
const void *rhs)
const
757 return QPartialOrdering::Unordered;
758 if (d_ptr && d_ptr->flags & QMetaType::IsPointer)
759 return threeWayCompare(*
reinterpret_cast<
const void *
const *>(lhs),
760 *
reinterpret_cast<
const void *
const *>(rhs));
761 if (d_ptr && d_ptr->lessThan) {
762 if (d_ptr->equals && d_ptr->equals(d_ptr, lhs, rhs))
763 return QPartialOrdering::Equivalent;
764 if (d_ptr->lessThan(d_ptr, lhs, rhs))
765 return QPartialOrdering::Less;
766 if (d_ptr->lessThan(d_ptr, rhs, lhs))
767 return QPartialOrdering::Greater;
769 return QPartialOrdering::Equivalent;
771 return QPartialOrdering::Unordered;
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790bool QMetaType::equals(
const void *lhs,
const void *rhs)
const
795 if (d_ptr->flags & QMetaType::IsPointer)
796 return *
reinterpret_cast<
const void *
const *>(lhs) == *
reinterpret_cast<
const void *
const *>(rhs);
799 return d_ptr->equals(d_ptr, lhs, rhs);
800 if (d_ptr->lessThan && !d_ptr->lessThan(d_ptr, lhs, rhs) && !d_ptr->lessThan(d_ptr, rhs, lhs))
807
808
809
810
811
812
813
814
815
818
819
820
821
822
823
824
825
826
829
830
831
832
833
834
835
836
839
840
841
842
843
844
845
846
848bool QMetaType::isDefaultConstructible(
const QtPrivate::QMetaTypeInterface *iface)
noexcept
850 return !isInterfaceFor<
void>(iface) && QtMetaTypePrivate::isDefaultConstructible(iface);
853bool QMetaType::isCopyConstructible(
const QtPrivate::QMetaTypeInterface *iface)
noexcept
855 return !isInterfaceFor<
void>(iface) && QtMetaTypePrivate::isCopyConstructible(iface);
858bool QMetaType::isMoveConstructible(
const QtPrivate::QMetaTypeInterface *iface)
noexcept
860 return !isInterfaceFor<
void>(iface) && QtMetaTypePrivate::isMoveConstructible(iface);
863bool QMetaType::isDestructible(
const QtPrivate::QMetaTypeInterface *iface)
noexcept
865 return !isInterfaceFor<
void>(iface) && QtMetaTypePrivate::isDestructible(iface);
869
870
871
872
873
874bool QMetaType::isEqualityComparable()
const
876 return d_ptr && (d_ptr->flags & QMetaType::IsPointer || d_ptr->equals !=
nullptr || d_ptr->lessThan !=
nullptr);
880
881
882
883
884
885bool QMetaType::isOrdered()
const
887 return d_ptr && (d_ptr->flags & QMetaType::IsPointer || d_ptr->lessThan !=
nullptr);
892
893
894void QMetaType::unregisterMetaType(QMetaType type)
896 const QtPrivate::QMetaTypeInterface *d_ptr = type.d_ptr;
900 const int typeId = d_ptr->typeId.loadRelaxed();
901 if (typeId < QMetaType::User)
906 if (
auto reg = customTypeRegistry()) {
907 Q_ASSERT(reg->getCustomType(typeId) == d_ptr);
908 reg->unregisterDynamicType(typeId);
911 const_cast<QtPrivate::QMetaTypeInterface *>(d_ptr)->typeId.storeRelease(0);
915
916
917
918
919
922
923
924
925
926
927
930
931
932
933
934
935
938bool QMetaTypeModuleHelper::convert(
const void *,
int,
void *,
int)
const
943#define QT_ADD_STATIC_METATYPE(MetaTypeName, MetaTypeId, RealName)
944 { #RealName, sizeof(#RealName) - 1
, MetaTypeId },
946#define QT_ADD_STATIC_METATYPE_ALIASES_ITER(MetaTypeName, MetaTypeId, AliasingName, RealNameStr)
947 { RealNameStr, sizeof(RealNameStr) - 1
, QMetaType::MetaTypeName },
951static const struct {
const char * typeName;
int typeNameLength;
int type; } types[] = {
955 {
nullptr, 0, QMetaType::UnknownType}
959static constexpr struct : QMetaTypeModuleHelper
961 template<
typename T,
typename LiteralWrapper =
962 std::conditional_t<std::is_same_v<T, QString>, QLatin1StringView,
const char *>>
963 static inline bool convertToBool(
const T &source)
965 T str = source.toLower();
966 return !(str.isEmpty() || str == LiteralWrapper(
"0") || str == LiteralWrapper(
"false"));
981 bool convert(
const void *from,
int fromTypeId,
void *to,
int toTypeId)
const override
983 Q_ASSERT(fromTypeId != toTypeId);
986 bool onlyCheck = (from ==
nullptr && to ==
nullptr);
989 Q_ASSERT(onlyCheck || (
bool(from) &&
bool(to)));
992 using SChar =
signed char;
993 using UChar =
unsigned char;
995 using UShort =
unsigned short;
997 using UInt =
unsigned int;
999 using LongLong = qlonglong;
1000 using ULong =
unsigned long;
1001 using ULongLong = qulonglong;
1002 using Float =
float;
1003 using Double =
double;
1005 using Nullptr =
std::nullptr_t;
1006 using Char16 =
char16_t;
1007 using Char32 =
char32_t;
1009#define QMETATYPE_CONVERTER_ASSIGN_DOUBLE(To, From)
1011#define QMETATYPE_CONVERTER_ASSIGN_NUMBER(To, From)
1013#ifndef QT_BOOTSTRAPPED
1014#define CONVERT_CBOR_AND_JSON(To)
1016 if constexpr(std::is_same_v<To, Bool>) {
1017 if (!source.isBool())
1019 result = source.toBool();
1021 if (!source.isInteger() && !source.isDouble())
1023 if constexpr(std::is_integral_v<To>)
1024 result = source.toInteger();
1026 result = source.toDouble();
1031 if constexpr(std::is_same_v<To, Bool>) {
1032 if (!source.isBool())
1034 result = source.toBool();
1036 if (!source.isDouble())
1038 if constexpr(std::is_integral_v<To>)
1039 result = source.toInteger();
1041 result = source.toDouble();
1046#define CONVERT_CBOR_AND_JSON(To)
1049#define INTEGRAL_CONVERTER(To)
1067 if constexpr(std::is_same_v<To, bool>)
1068 result = (ok = true, convertToBool(source));
1069 else if constexpr(std::is_signed_v<To>)
1070 result = To(source.toLongLong(&ok));
1072 result = To(source.toULongLong(&ok));
1077 if constexpr(std::is_same_v<To, bool>)
1078 result = (ok = true, convertToBool(source));
1079 else if constexpr(std::is_signed_v<To>)
1080 result = To(source.toLongLong(&ok));
1082 result = To(source.toULongLong(&ok));
1087#define FLOAT_CONVERTER(To)
1104 result = source.toDouble(&ok);
1109 result = source.toDouble(&ok);
1114 switch (makePair(toTypeId, fromTypeId)) {
1132#ifndef QT_BOOTSTRAPPED
1135 if (source.isUrl()) {
1136 result = source.toUrl();
1142#if QT_CONFIG(itemmodel)
1143 QMETATYPE_CONVERTER_ASSIGN(QModelIndex, QPersistentModelIndex);
1144 QMETATYPE_CONVERTER_ASSIGN(QPersistentModelIndex, QModelIndex);
1148#define QMETATYPE_CONVERTER_ASSIGN_QCHAR(From)
1169 result = source ? QStringLiteral(
"true") : QStringLiteral(
"false");
1181 result = QString::number(source,
'g', QLocale::FloatingPointShortest);
1185 result = QString::number(source,
'g', QLocale::FloatingPointShortest);
1189 result = QString::fromLatin1(&source, 1);
1194 result = QString::fromLatin1(&s, 1);
1199 result = QString::fromLatin1(&s, 1);
1203 result = QChar(source);
1207 result = QChar::fromUcs4(source).operator QStringView().toString();
1210#if QT_CONFIG(datestring)
1211 QMETATYPE_CONVERTER(QString, QDate, result = source.toString(Qt::ISODate);
return true;);
1212 QMETATYPE_CONVERTER(QString, QTime, result = source.toString(Qt::ISODateWithMs);
return true;);
1213 QMETATYPE_CONVERTER(QString, QDateTime, result = source.toString(Qt::ISODateWithMs);
return true;);
1217 return (source.size() == 1) ? (result = source.at(0),
true) :
false;
1219#ifndef QT_BOOTSTRAPPED
1222 if (source.isString() || source.isNull()) {
1223 result = source.toString();
1229 QMETATYPE_CONVERTER(QString, Nullptr, Q_UNUSED(source); result = QString();
return true;);
1234 result = source ?
"true" :
"false";
1249 result = QByteArray::number(source,
'g', QLocale::FloatingPointShortest);
1253 result = QByteArray::number(source,
'g', QLocale::FloatingPointShortest);
1263#ifndef QT_NO_GEOM_VARIANT
1274 QMETATYPE_CONVERTER(QStringList, QString, result = QStringList() << source;
return true;);
1276#ifndef QT_NO_VARIANT
1278 result.reserve(source.size());
1279 for (
const auto &v: source)
1280 result.append(v.toByteArray());
1284 result.reserve(source.size());
1285 for (
const auto &v: source)
1286 result.append(QVariant(v));
1291 result.reserve(source.size());
1292 for (
const auto &v: source)
1293 result.append(v.toString());
1297 result.reserve(source.size());
1298 for (
const auto &v: source)
1299 result.append(QVariant(v));
1304 for (
auto it = source.begin(); it != source.end(); ++it)
1305 result.insert(it.key(), it.value());
1309 for (
auto it = source.begin(); it != source.end(); ++it)
1310 result.insert(it.key(), it.value());
1314#ifndef QT_BOOTSTRAPPED
1317 if (source.isContainer() || source.isTag())
1319 result = source.toVariant().toString();
1324 if (source.isByteArray()) {
1325 result = source.toByteArray();
1332 if (!source.isUuid())
1334 result = source.toUuid();
1339 if (!source.isArray())
1341 result = source.toArray().toVariantList();
1344 QMETATYPE_CONVERTER(QCborValue, QVariantMap, result = QCborMap::fromVariantMap(source);
return true;);
1346 if (!source.isMap())
1348 result = source.toMap().toVariantMap();
1351 QMETATYPE_CONVERTER(QCborValue, QVariantHash, result = QCborMap::fromVariantHash(source);
return true;);
1353 if (!source.isMap())
1355 result = source.toMap().toVariantHash();
1358#if QT_CONFIG(regularexpression)
1359 QMETATYPE_CONVERTER(QCborValue, QRegularExpression, result = QCborValue(source);
return true;);
1360 QMETATYPE_CONVERTER(QRegularExpression, QCborValue,
1361 if (!source.isRegularExpression())
1363 result = source.toRegularExpression();
1370 result = QCborValue(QCborValue::Null);
1375 return source.isNull();
1392 result = QCborArray::fromStringList(source);
1395#if QT_CONFIG(datestring)
1396 QMETATYPE_CONVERTER(QCborValue, QDate,
1397 result = QCborValue(source.startOfDay());
1403 result = QCborValue::fromJsonValue(source);
1407 result = QCborMap::fromJsonObject(source);
1411 result = QCborArray::fromJsonArray(source);
1415 QJsonDocument doc = source;
1417 result = QCborArray::fromJsonArray(doc.array());
1419 result = QCborMap::fromJsonObject(doc.object());
1425#if QT_CONFIG(datestring)
1426 QMETATYPE_CONVERTER_ASSIGN(QCborValue, QDateTime);
1427 QMETATYPE_CONVERTER(QDateTime, QCborValue,
1428 if (source.isDateTime()) {
1429 result = source.toDateTime();
1438 if (source.isSimpleType()) {
1439 result = source.toSimpleType();
1447 QMETATYPE_CONVERTER(QCborArray, QStringList, result = QCborArray::fromStringList(source);
return true;);
1448 QMETATYPE_CONVERTER(QCborMap, QVariantMap, result = QCborMap::fromVariantMap(source);
return true;);
1450 QMETATYPE_CONVERTER(QCborMap, QVariantHash, result = QCborMap::fromVariantHash(source);
return true;);
1451 QMETATYPE_CONVERTER(QVariantHash, QCborMap, result = source.toVariantHash();
return true;);
1454 if (!source.isArray())
1456 result = source.toArray();
1460 if (!source.isArray())
1462 result = QCborArray::fromJsonArray(source.array());
1466 if (!source.isArray())
1468 result = QCborArray::fromJsonArray(source.toArray());
1472 result = QCborArray::fromJsonArray(source);
1476 if (!source.isMap())
1478 result = source.toMap();
1482 if (source.isArray())
1484 result = QCborMap::fromJsonObject(source.object());
1488 if (!source.isObject())
1490 result = QCborMap::fromJsonObject(source.toObject());
1494 result = QCborMap::fromJsonObject(source);
1500 if (!source.isArray())
1502 result = source.toArray().toVariantList();
1507 if (!source.isObject())
1509 result = source.toObject().toVariantMap();
1512 QMETATYPE_CONVERTER(QVariantMap, QJsonObject, result = source.toVariantMap();
return true;);
1514 if (!source.isObject())
1516 result = source.toObject().toVariantHash();
1519 QMETATYPE_CONVERTER(QVariantHash, QJsonObject, result = source.toVariantHash();
return true;);
1522 QMETATYPE_CONVERTER(QJsonArray, QStringList, result = QJsonArray::fromStringList(source);
return true;);
1525 if (!source.isArray())
1527 result = source.toArray();
1531 if (!source.isArray())
1533 result = source.array();
1537 if (!source.isArray())
1539 result = source.toArray().toJsonArray();
1543 QMETATYPE_CONVERTER(QJsonObject, QVariantMap, result = QJsonObject::fromVariantMap(source);
return true;);
1544 QMETATYPE_CONVERTER(QJsonObject, QVariantHash, result = QJsonObject::fromVariantHash(source);
return true;);
1546 if (!source.isObject())
1548 result = source.toObject();
1552 if (source.isArray())
1554 result = source.object();
1558 if (!source.isMap())
1560 result = source.toMap().toJsonObject();
1563 QMETATYPE_CONVERTER(QJsonObject, QCborMap, result = source.toJsonObject();
return true; );
1567 result = QJsonValue(QJsonValue::Null);
1572 return source.isNull();
1575 result = QJsonValue(source);
1592 result = QJsonValue(QJsonArray::fromStringList(source));
1596 result = QJsonValue(QJsonArray::fromVariantList(source));
1600 result = QJsonValue(QJsonObject::fromVariantMap(source));
1604 result = QJsonValue(QJsonObject::fromVariantHash(source));
1616 QJsonDocument doc = source;
1617 result = doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object());
1621 result = source.toJsonValue();
1625 result = source.toJsonObject();
1629 result = source.toJsonArray();
1638#if QT_CONFIG(datestring)
1639 QMETATYPE_CONVERTER(QDate, QString,
1640 result = QDate::fromString(source, Qt::ISODate);
1641 return result.isValid();
1643 QMETATYPE_CONVERTER(QTime, QString,
1644 result = QTime::fromString(source, Qt::ISODate);
1645 return result.isValid();
1647 QMETATYPE_CONVERTER(QDateTime, QString,
1648 result = QDateTime::fromString(source, Qt::ISODate);
1649 return result.isValid();
1656} metatypeHelper = {};
1663 if (type <= QMetaType::LastCoreType)
1664 return &metatypeHelper;
1665 if (type >= QMetaType::FirstGuiType && type <= QMetaType::LastGuiType)
1666 return qMetaTypeGuiHelper;
1667 else if (type >= QMetaType::FirstWidgetsType && type <= QMetaType::LastWidgetsType)
1668 return qMetaTypeWidgetsHelper;
1672template<
typename T,
typename Key>
1678 const QWriteLocker locker(&lock);
1684 const QReadLocker locker(&lock);
1685 return map.contains(k);
1690 const QWriteLocker locker(&lock);
1691 const qsizetype oldSize = map.size();
1693 if (map.size() == oldSize)
1701 const QReadLocker locker(&lock);
1702 auto it = map.find(k);
1703 return it == map.end() ?
nullptr :
std::addressof(*it);
1708 const Key k(from, to);
1709 const QWriteLocker locker(&lock);
1713 mutable QReadWriteLock lock;
1717using QMetaTypeConverterRegistry
1718 = QMetaTypeFunctionRegistry<QMetaType::ConverterFunction, std::pair<
int,
int>>;
1720Q_GLOBAL_STATIC(QMetaTypeConverterRegistry, customTypesConversionRegistry)
1722using QMetaTypeMutableViewRegistry
1723 = QMetaTypeFunctionRegistry<QMetaType::MutableViewFunction, std::pair<
int,
int>>;
1724Q_GLOBAL_STATIC(QMetaTypeMutableViewRegistry, customTypesMutableViewRegistry)
1727
1728
1729
1730
1731
1732
1733
1736
1737
1738
1739
1740
1741
1742
1743
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1771
1772
1773
1774
1776
1777bool QMetaType::registerConverterFunction(
const ConverterFunction &f, QMetaType from, QMetaType to)
1779 if (!customTypesConversionRegistry()->insertIfNotContains({from.id(), to.id()}, f)) {
1780 qWarning(
"Type conversion already registered from type %s to type %s",
1781 from.name(), to.name());
1788
1789
1790
1791
1792
1793
1794
1797
1798
1799
1800
1801
1802
1805
1806
1807
1809
1810bool QMetaType::registerMutableViewFunction(
const MutableViewFunction &f, QMetaType from, QMetaType to)
1812 if (!customTypesMutableViewRegistry()->insertIfNotContains({from.id(), to.id()}, f)) {
1813 qWarning(
"Mutable view on type already registered from type %s to type %s",
1814 from.name(), to.name());
1822
1823void QMetaType::unregisterMutableViewFunction(QMetaType from, QMetaType to)
1825 if (customTypesMutableViewRegistry.isDestroyed())
1827 customTypesMutableViewRegistry()->remove(from.id(), to.id());
1831
1832
1834
1835void QMetaType::unregisterConverterFunction(QMetaType from, QMetaType to)
1837 if (customTypesConversionRegistry.isDestroyed())
1839 customTypesConversionRegistry()->remove(from.id(), to.id());
1842#ifndef QT_NO_DEBUG_STREAM
1845
1846
1848
1849QDebug operator<<(QDebug d, QMetaType m)
1851 const QDebugStateSaver saver(d);
1852 return d.nospace() <<
"QMetaType(" << m.name() <<
")";
1856
1857
1859
1860bool QMetaType::debugStream(QDebug& dbg,
const void *rhs)
1862 if (d_ptr && d_ptr->flags & QMetaType::IsPointer) {
1863 dbg << *
reinterpret_cast<
const void *
const *>(rhs);
1866 if (d_ptr && d_ptr->debugStream) {
1867 d_ptr->debugStream(d_ptr, dbg, rhs);
1874
1875
1876
1877
1880
1881
1882
1883
1884
1885
1888
1889
1890
1891
1892
1893
1894
1897
1898
1899
1901
1902bool QMetaType::hasRegisteredDebugStreamOperator()
const
1904 return d_ptr && d_ptr->debugStream !=
nullptr;
1908#ifndef QT_NO_QOBJECT
1910
1912
1913static QMetaEnum metaEnumFromType(QMetaType t)
1915 if (t.flags() & QMetaType::IsEnumeration) {
1916 if (
const QMetaObject *metaObject = t.metaObject()) {
1917 QByteArrayView qflagsNamePrefix =
"QFlags<";
1919 if (enumName.endsWith(
'>') && enumName.startsWith(qflagsNamePrefix)) {
1922 enumName = enumName.sliced(qflagsNamePrefix.size());
1924 if (qsizetype lastColon = enumName.lastIndexOf(
':'); lastColon != -1)
1925 enumName = enumName.sliced(lastColon + 1);
1926 return metaObject->enumerator(metaObject->indexOfEnumerator(enumName));
1933static bool convertFromEnum(QMetaType fromType,
const void *from, QMetaType toType,
void *to)
1936 if (fromType.flags() & QMetaType::IsUnsignedEnumeration) {
1938 switch (fromType.sizeOf()) {
1940 ull = *
static_cast<
const unsigned char *>(from);
1943 ull = *
static_cast<
const unsigned short *>(from);
1946 ull = *
static_cast<
const unsigned int *>(from);
1949 ull = *
static_cast<
const quint64 *>(from);
1954 if (toType.id() == QMetaType::ULongLong) {
1955 *
static_cast<qulonglong *>(to) = ull;
1958 if (toType.id() != QMetaType::QString && toType.id() != QMetaType::QByteArray)
1959 return QMetaType::convert(QMetaType::fromType<qulonglong>(), &ull, toType, to);
1960 ll = qlonglong(ull);
1962 switch (fromType.sizeOf()) {
1964 ll = *
static_cast<
const signed char *>(from);
1967 ll = *
static_cast<
const short *>(from);
1970 ll = *
static_cast<
const int *>(from);
1973 ll = *
static_cast<
const qint64 *>(from);
1978 if (toType.id() == QMetaType::LongLong) {
1979 *
static_cast<qlonglong *>(to) = ll;
1982 if (toType.id() != QMetaType::QString && toType.id() != QMetaType::QByteArray)
1983 return QMetaType::convert(QMetaType::fromType<qlonglong>(), &ll, toType, to);
1985#ifndef QT_NO_QOBJECT
1986 QMetaEnum en = metaEnumFromType(fromType);
1990 if (toType.id() == QMetaType::QString)
1991 *
static_cast<QString *>(to) = QString::fromUtf8(keys);
1995 const char *key = en.valueToKey(ll);
1996 if (toType.id() == QMetaType::QString)
1997 *
static_cast<QString *>(to) = QString::fromUtf8(key);
2004 if (toType.id() == QMetaType::QString || toType.id() == QMetaType::QByteArray)
2005 return QMetaType::convert(QMetaType::fromType<qlonglong>(), &ll, toType, to);
2009static bool convertToEnum(QMetaType fromType,
const void *from, QMetaType toType,
void *to)
2011 int fromTypeId = fromType.id();
2012 qlonglong value = -1;
2014#ifndef QT_NO_QOBJECT
2015 if (fromTypeId == QMetaType::QString || fromTypeId == QMetaType::QByteArray) {
2016 QMetaEnum en = metaEnumFromType(toType);
2018 QByteArray keys = (fromTypeId == QMetaType::QString)
2019 ?
static_cast<
const QString *>(from)->toUtf8()
2020 : *
static_cast<
const QByteArray *>(from);
2021 if (
auto v = en.keysToValue64(keys.constData())) {
2029 if (fromTypeId == QMetaType::LongLong) {
2030 value = *
static_cast<
const qlonglong *>(from);
2033 ok = QMetaType::convert(fromType, from, QMetaType::fromType<qlonglong>(), &value);
2040 switch (toType.sizeOf()) {
2042 *
static_cast<
signed char *>(to) = value;
2045 *
static_cast<qint16 *>(to) = value;
2048 *
static_cast<qint32 *>(to) = value;
2051 *
static_cast<qint64 *>(to) = value;
2054 Q_UNREACHABLE_RETURN(
false);
2058#ifndef QT_BOOTSTRAPPED
2059static bool convertIterableToVariantList(QMetaType fromType,
const void *from,
void *to)
2062 if (!QMetaType::convert(fromType, from, QMetaType::fromType<QSequentialIterable>(), &list))
2067 l.reserve(list.size());
2068 auto end = list.end();
2069 for (
auto it = list.begin(); it != end; ++it)
2074static bool convertIterableToVariantMap(QMetaType fromType,
const void *from,
void *to)
2077 if (!QMetaType::convert(fromType, from, QMetaType::fromType<QAssociativeIterable>(), &map))
2080 QVariantMap &h = *
static_cast<QVariantMap *>(to);
2082 auto end = map.end();
2083 for (
auto it = map.begin(); it != end; ++it)
2084 h.insert(it.key().toString(), it.value());
2088static bool convertIterableToVariantHash(QMetaType fromType,
const void *from,
void *to)
2091 if (!QMetaType::convert(fromType, from, QMetaType::fromType<QAssociativeIterable>(), &map))
2094 QVariantHash &h = *
static_cast<QVariantHash *>(to);
2096 h.reserve(map.size());
2097 auto end = map.end();
2098 for (
auto it = map.begin(); it != end; ++it)
2099 h.insert(it.key().toString(), it.value());
2103static bool convertIterableToVariantPair(QMetaType fromType,
const void *from,
void *to)
2106 const auto f = customTypesConversionRegistry()->function({fromType.id(), targetId});
2114 QVariant v1(pi._metaType_first);
2116 if (pi._metaType_first == QMetaType::fromType<QVariant>())
2119 dataPtr = v1.data();
2122 QVariant v2(pi._metaType_second);
2123 if (pi._metaType_second == QMetaType::fromType<QVariant>())
2126 dataPtr = v2.data();
2129 *
static_cast<QVariantPair *>(to) = QVariantPair(v1, v2);
2133static bool convertToSequentialIterable(QMetaType fromType,
const void *from,
void *to)
2136 const int fromTypeId = fromType.id();
2138 QSequentialIterable &i = *
static_cast<QSequentialIterable *>(to);
2139 switch (fromTypeId) {
2140 case QMetaType::QVariantList:
2141 i = QSequentialIterable(
reinterpret_cast<
const QVariantList *>(from));
2143 case QMetaType::QStringList:
2144 i = QSequentialIterable(
reinterpret_cast<
const QStringList *>(from));
2146 case QMetaType::QByteArrayList:
2147 i = QSequentialIterable(
reinterpret_cast<
const QByteArrayList *>(from));
2149 case QMetaType::QString:
2150 i = QSequentialIterable(
reinterpret_cast<
const QString *>(from));
2152 case QMetaType::QByteArray:
2153 i = QSequentialIterable(
reinterpret_cast<
const QByteArray *>(from));
2157 if (QMetaType::convert(
2158 fromType, from, QMetaType::fromType<QIterable<QMetaSequence>>(), &impl)) {
2159 i = std::move(impl);
2168static bool canConvertToSequentialIterable(QMetaType fromType)
2170 switch (fromType.id()) {
2171 case QMetaType::QVariantList:
2172 case QMetaType::QStringList:
2173 case QMetaType::QByteArrayList:
2174 case QMetaType::QString:
2175 case QMetaType::QByteArray:
2178 return QMetaType::canConvert(fromType, QMetaType::fromType<QIterable<QMetaSequence>>());
2182static bool canImplicitlyViewAsSequentialIterable(QMetaType fromType)
2184 switch (fromType.id()) {
2185 case QMetaType::QVariantList:
2186 case QMetaType::QStringList:
2187 case QMetaType::QByteArrayList:
2188 case QMetaType::QString:
2189 case QMetaType::QByteArray:
2192 return QMetaType::canView(
2193 fromType, QMetaType::fromType<QIterable<QMetaSequence>>());
2197static bool viewAsSequentialIterable(QMetaType fromType,
void *from,
void *to)
2200 const int fromTypeId = fromType.id();
2202 QSequentialIterable &i = *
static_cast<QSequentialIterable *>(to);
2203 switch (fromTypeId) {
2204 case QMetaType::QVariantList:
2205 i = QSequentialIterable(
reinterpret_cast<QVariantList *>(from));
2207 case QMetaType::QStringList:
2208 i = QSequentialIterable(
reinterpret_cast<QStringList *>(from));
2210 case QMetaType::QByteArrayList:
2211 i = QSequentialIterable(
reinterpret_cast<QByteArrayList *>(from));
2213 case QMetaType::QString:
2214 i = QSequentialIterable(
reinterpret_cast<QString *>(from));
2216 case QMetaType::QByteArray:
2217 i = QSequentialIterable(
reinterpret_cast<QByteArray *>(from));
2220 QIterable<QMetaSequence> j(QMetaSequence(),
nullptr);
2221 if (QMetaType::view(
2222 fromType, from, QMetaType::fromType<QIterable<QMetaSequence>>(), &j)) {
2232static bool convertToAssociativeIterable(QMetaType fromType,
const void *from,
void *to)
2236 QAssociativeIterable &i = *
static_cast<QAssociativeIterable *>(to);
2237 if (fromType.id() == QMetaType::QVariantMap) {
2238 i = QAssociativeIterable(
reinterpret_cast<
const QVariantMap *>(from));
2241 if (fromType.id() == QMetaType::QVariantHash) {
2242 i = QAssociativeIterable(
reinterpret_cast<
const QVariantHash *>(from));
2247 if (QMetaType::convert(
2248 fromType, from, QMetaType::fromType<QIterable<QMetaAssociation>>(), &impl)) {
2249 i = std::move(impl);
2256static bool canConvertMetaObject(QMetaType fromType, QMetaType toType)
2258 if ((fromType.flags() & QMetaType::IsPointer) != (toType.flags() & QMetaType::IsPointer))
2261 const QMetaObject *f = fromType.metaObject();
2262 const QMetaObject *t = toType.metaObject();
2264 return f->inherits(t) || (t->inherits(f));
2269static bool canConvertToAssociativeIterable(QMetaType fromType)
2271 switch (fromType.id()) {
2272 case QMetaType::QVariantMap:
2273 case QMetaType::QVariantHash:
2276 return QMetaType::canConvert(fromType, QMetaType::fromType<QIterable<QMetaAssociation>>());
2280static bool canImplicitlyViewAsAssociativeIterable(QMetaType fromType)
2282 switch (fromType.id()) {
2283 case QMetaType::QVariantMap:
2284 case QMetaType::QVariantHash:
2287 return QMetaType::canView(
2288 fromType, QMetaType::fromType<QIterable<QMetaAssociation>>());
2292static bool viewAsAssociativeIterable(QMetaType fromType,
void *from,
void *to)
2295 int fromTypeId = fromType.id();
2297 QAssociativeIterable &i = *
static_cast<QAssociativeIterable *>(to);
2298 if (fromTypeId == QMetaType::QVariantMap) {
2299 i = QAssociativeIterable(
reinterpret_cast<QVariantMap *>(from));
2302 if (fromTypeId == QMetaType::QVariantHash) {
2303 i = QAssociativeIterable(
reinterpret_cast<QVariantHash *>(from));
2307 QIterable<QMetaAssociation> j(QMetaAssociation(),
nullptr);
2308 if (QMetaType::view(
2309 fromType, from, QMetaType::fromType<QIterable<QMetaAssociation>>(), &j)) {
2317static bool convertMetaObject(QMetaType fromType,
const void *from, QMetaType toType,
void *to)
2320 if ((fromType.flags() & QMetaType::PointerToQObject) && (toType.flags() & QMetaType::PointerToQObject)) {
2321 QObject *fromObject = *
static_cast<QObject *
const *>(from);
2323 if (fromObject && fromObject->metaObject()->inherits(toType.metaObject())) {
2324 *
static_cast<QObject **>(to) = toType.metaObject()->cast(fromObject);
2326 }
else if (!fromObject && fromType.metaObject()) {
2328 *
static_cast<
void **>(to) =
nullptr;
2329 return fromType.metaObject()->inherits(toType.metaObject());
2331 }
else if ((fromType.flags() & QMetaType::IsPointer) == (toType.flags() & QMetaType::IsPointer)) {
2333 const QMetaObject *f = fromType.metaObject();
2334 const QMetaObject *t = toType.metaObject();
2335 if (f && t && f->inherits(t)) {
2336 toType.destruct(to);
2337 toType.construct(to, from);
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2358
2359
2360
2361
2362
2364
2365bool QMetaType::convert(QMetaType fromType,
const void *from, QMetaType toType,
void *to)
2367 if (!fromType.isValid() || !toType.isValid())
2370 if (fromType == toType) {
2372 fromType.destruct(to);
2373 fromType.construct(to, from);
2377 int fromTypeId = fromType.id();
2378 int toTypeId = toType.id();
2380 if (
auto moduleHelper = qModuleHelperForType(qMax(fromTypeId, toTypeId))) {
2381 if (moduleHelper->convert(from, fromTypeId, to, toTypeId))
2384 const auto f = customTypesConversionRegistry()->function({fromTypeId, toTypeId});
2386 return (*f)(from, to);
2388 if (fromType.flags() & QMetaType::IsEnumeration)
2389 return convertFromEnum(fromType, from, toType, to);
2390 if (toType.flags() & QMetaType::IsEnumeration)
2391 return convertToEnum(fromType, from, toType, to);
2392 if (toTypeId == Nullptr) {
2393 *
static_cast<std::nullptr_t *>(to) =
nullptr;
2394 if (fromType.flags() & QMetaType::IsPointer) {
2395 if (*
static_cast<
const void *
const *>(from) ==
nullptr)
2400#ifndef QT_BOOTSTRAPPED
2401# ifndef QT_NO_VARIANT
2402 if (toTypeId == QVariantPair && convertIterableToVariantPair(fromType, from, to))
2406 if (toTypeId == QVariantList && convertIterableToVariantList(fromType, from, to))
2409 if (toTypeId == QVariantMap && convertIterableToVariantMap(fromType, from, to))
2412 if (toTypeId == QVariantHash && convertIterableToVariantHash(fromType, from, to))
2416 if (toTypeId == qMetaTypeId<QSequentialIterable>())
2417 return convertToSequentialIterable(fromType, from, to);
2419 if (toTypeId == qMetaTypeId<QAssociativeIterable>())
2420 return convertToAssociativeIterable(fromType, from, to);
2422 return convertMetaObject(fromType, from, toType, to);
2429
2430
2432
2433bool QMetaType::view(QMetaType fromType,
void *from, QMetaType toType,
void *to)
2435 if (!fromType.isValid() || !toType.isValid())
2438 int fromTypeId = fromType.id();
2439 int toTypeId = toType.id();
2441 const auto f = customTypesMutableViewRegistry()->function({fromTypeId, toTypeId});
2443 return (*f)(from, to);
2445#ifndef QT_BOOTSTRAPPED
2446 if (toTypeId == qMetaTypeId<QSequentialIterable>())
2447 return viewAsSequentialIterable(fromType, from, to);
2449 if (toTypeId == qMetaTypeId<QAssociativeIterable>())
2450 return viewAsAssociativeIterable(fromType, from, to);
2452 return convertMetaObject(fromType, from, toType, to);
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2474
2475bool QMetaType::canView(QMetaType fromType, QMetaType toType)
2477 int fromTypeId = fromType.id();
2478 int toTypeId = toType.id();
2480 if (fromTypeId == UnknownType || toTypeId == UnknownType)
2483 const auto f = customTypesMutableViewRegistry()->function({fromTypeId, toTypeId});
2487#ifndef QT_BOOTSTRAPPED
2488 if (toTypeId == qMetaTypeId<QSequentialIterable>())
2489 return canImplicitlyViewAsSequentialIterable(fromType);
2491 if (toTypeId == qMetaTypeId<QAssociativeIterable>())
2492 return canImplicitlyViewAsAssociativeIterable(fromType);
2494 if (canConvertMetaObject(fromType, toType))
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2571
2572bool QMetaType::canConvert(QMetaType fromType, QMetaType toType)
2574 int fromTypeId = fromType.id();
2575 int toTypeId = toType.id();
2577 if (fromTypeId == UnknownType || toTypeId == UnknownType)
2580 if (fromTypeId == toTypeId)
2583 if (
auto moduleHelper = qModuleHelperForType(qMax(fromTypeId, toTypeId))) {
2584 if (moduleHelper->convert(
nullptr, fromTypeId,
nullptr, toTypeId))
2587 const ConverterFunction *
const f =
2588 customTypesConversionRegistry()->function(std::make_pair(fromTypeId, toTypeId));
2592#ifndef QT_BOOTSTRAPPED
2593 if (toTypeId == qMetaTypeId<QSequentialIterable>())
2594 return canConvertToSequentialIterable(fromType);
2596 if (toTypeId == qMetaTypeId<QAssociativeIterable>())
2597 return canConvertToAssociativeIterable(fromType);
2599#ifndef QT_NO_VARIANT
2600 if (toTypeId == QVariantList
2601 && canConvert(fromType, QMetaType::fromType<QSequentialIterable>())) {
2605 if ((toTypeId == QVariantHash || toTypeId == QVariantMap)
2606 && canConvert(fromType, QMetaType::fromType<QAssociativeIterable>())) {
2610 if (toTypeId == QVariantPair && hasRegisteredConverterFunction(
2611 fromType, QMetaType::fromType<QtMetaTypePrivate::QPairVariantInterfaceImpl>()))
2615 if (fromType.flags() & IsEnumeration) {
2616 if (toTypeId == QString || toTypeId == QByteArray)
2618 return canConvert(QMetaType(LongLong), toType);
2620 if (toType.flags() & IsEnumeration) {
2621 if (fromTypeId == QString || fromTypeId == QByteArray)
2623 return canConvert(fromType, QMetaType(LongLong));
2625 if (toTypeId == Nullptr && fromType.flags() & IsPointer)
2627#ifndef QT_BOOTSTRAPPED
2628 if (canConvertMetaObject(fromType, toType))
2636
2637
2638
2639
2640
2641
2642
2645
2646
2647
2648
2649
2652
2653
2655
2656bool QMetaType::hasRegisteredConverterFunction(QMetaType fromType, QMetaType toType)
2658 return customTypesConversionRegistry()->contains({fromType.id(), toType.id()});
2662
2664
2665bool QtPrivate::hasRegisteredConverterFunctionToPairVariantInterface(QMetaType m)
2667 const QMetaType to = QMetaType::fromType<QtMetaTypePrivate::QPairVariantInterfaceImpl>();
2668 return QMetaType::hasRegisteredConverterFunction(m, to);
2672
2674
2675bool QtPrivate::hasRegisteredConverterFunctionToIterableMetaSequence(QMetaType m)
2677 const QMetaType to = QMetaType::fromType<QIterable<QMetaSequence>>();
2678 return QMetaType::hasRegisteredConverterFunction(m, to);
2682
2684
2685bool QtPrivate::hasRegisteredConverterFunctionToIterableMetaAssociation(QMetaType m)
2687 const QMetaType to = QMetaType::fromType<QIterable<QMetaAssociation>>();
2688 return QMetaType::hasRegisteredConverterFunction(m, to);
2692
2693
2694
2695
2696
2699
2700
2702
2703bool QMetaType::hasRegisteredMutableViewFunction(QMetaType fromType, QMetaType toType)
2705 return customTypesMutableViewRegistry()->contains({fromType.id(), toType.id()});
2709
2711
2712bool QtPrivate::hasRegisteredMutableViewFunctionToIterableMetaSequence(QMetaType m)
2714 const QMetaType to = QMetaType::fromType<QIterable<QMetaSequence>>();
2715 return QMetaType::hasRegisteredMutableViewFunction(m, to);
2719
2721
2722bool QtPrivate::hasRegisteredMutableViewFunctionToIterableMetaAssociation(QMetaType m)
2724 const QMetaType to = QMetaType::fromType<QIterable<QMetaAssociation>>();
2725 return QMetaType::hasRegisteredMutableViewFunction(m, to);
2729
2730
2731
2732
2733
2734
2735
2736
2737
2740
2741
2742
2743
2744
2745
2746
2747
2748
2752
2753static inline int qMetaTypeStaticType(
const char *typeName,
int length)
2756 while (types[i].typeName && ((length != types[i].typeNameLength)
2757 || memcmp(typeName, types[i].typeName, length))) {
2760 return types[i].type;
2764
2765
2767
2768static int qMetaTypeCustomType_unlocked(
const char *typeName,
int length)
2770 if (customTypeRegistry.exists()) {
2771 auto reg = &*customTypeRegistry;
2772#if QT_CONFIG(thread)
2773 Q_ASSERT(!reg->lock.tryLockForWrite());
2775 if (
auto ti = reg->aliases.value(QByteArray::fromRawData(typeName, length),
nullptr)) {
2776 return ti->typeId.loadRelaxed();
2779 return QMetaType::UnknownType;
2783
2784
2785
2786
2788
2789void QMetaType::registerNormalizedTypedef(
const NS(QByteArray) & normalizedTypeName,
2792 if (!metaType.isValid())
2794 if (
auto reg = customTypeRegistry()) {
2795 QWriteLocker lock(®->lock);
2796 auto &al = reg->aliases[normalizedTypeName];
2799 al = metaType.d_ptr;
2807 if (typeId >= QMetaType::User) {
2808 if (customTypeRegistry.exists())
2809 iface = customTypeRegistry->getCustomType(typeId);
2811 if (
auto moduleHelper = qModuleHelperForType(typeId))
2812 iface = moduleHelper->interfaceForType(typeId);
2818
2819
2820
2822
2823bool QMetaType::isRegistered(
int type)
2825 return interfaceForTypeNoWarning(type) !=
nullptr;
2829enum NormalizeTypeMode {
2834template <NormalizeTypeMode tryNormalizedType>
2835static inline int qMetaTypeTypeImpl(
const char *typeName,
int length)
2838 return QMetaType::UnknownType;
2839 int type = qMetaTypeStaticType(typeName, length);
2840 if (type == QMetaType::UnknownType) {
2841 QReadLocker locker(&customTypeRegistry()->lock);
2842 type = qMetaTypeCustomType_unlocked(typeName, length);
2843#ifndef QT_NO_QOBJECT
2844 if ((type == QMetaType::UnknownType) && tryNormalizedType) {
2845 const NS(QByteArray) normalizedTypeName = QMetaObject::normalizedType(typeName);
2846 type = qMetaTypeStaticType(normalizedTypeName.constData(),
2847 normalizedTypeName.size());
2848 if (type == QMetaType::UnknownType) {
2849 type = qMetaTypeCustomType_unlocked(normalizedTypeName.constData(),
2850 normalizedTypeName.size());
2859
2860
2861
2862
2863
2864
2865
2866
2869
2870
2871
2872
2874
2875Q_CORE_EXPORT
int qMetaTypeTypeInternal(
const char *typeName)
2877 return qMetaTypeTypeImpl<DontNormalizeType>(typeName,
int(qstrlen(typeName)));
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2893#ifndef QT_NO_DATASTREAM
2895
2896
2897
2898
2899
2900
2901
2902
2904
2905bool QMetaType::save(QDataStream &stream,
const void *data)
const
2907 if (!data || !isValid())
2911 if (id() == QMetaType::Long) {
2912 stream << qlonglong(*(
long *)data);
2914 }
else if (id() == QMetaType::ULong) {
2915 stream << qlonglong(*(
unsigned long *)data);
2919 if (!d_ptr->dataStreamOut)
2922 d_ptr->dataStreamOut(d_ptr, stream, data);
2927
2928
2929
2930
2933
2934
2935
2936
2937
2938
2939
2940
2942
2943bool QMetaType::load(QDataStream &stream,
void *data)
const
2945 if (!data || !isValid())
2949 if (id() == QMetaType::Long) {
2952 *(
long *)data =
long(ll);
2954 }
else if (id() == QMetaType::ULong) {
2957 *(
unsigned long *)data = (
unsigned long)(ull);
2960 if (!d_ptr->dataStreamIn)
2963 d_ptr->dataStreamIn(d_ptr, stream, data);
2968
2969
2970
2972
2973bool QMetaType::hasRegisteredDataStreamOperators()
const
2976 if (type == QMetaType::Long || type == QMetaType::ULong)
2978 return d_ptr && d_ptr->dataStreamIn !=
nullptr && d_ptr->dataStreamOut !=
nullptr;
2982
2983
2984
2985
2986
2987
2989
2990QMetaType QMetaType::underlyingType()
const
2992 if (!d_ptr || !(flags() & IsEnumeration))
2995
2996
2997
2998
2999
3000
3001 if (flags() & IsUnsignedEnumeration) {
3004 return QMetaType::fromType<quint8>();
3006 return QMetaType::fromType<quint16>();
3008 return QMetaType::fromType<quint32>();
3010 return QMetaType::fromType<quint64>();
3017 return QMetaType::fromType<qint8>();
3019 return QMetaType::fromType<qint16>();
3021 return QMetaType::fromType<qint32>();
3023 return QMetaType::fromType<qint64>();
3033
3034
3035
3036
3040
3042
3043QMetaType QMetaType::fromName(QByteArrayView typeName)
3045 return QMetaType(qMetaTypeTypeImpl<TryNormalizeType>(typeName.data(), typeName.size()));
3049
3050
3051
3052
3053
3054
3055
3056
3059
3060
3061
3062
3063
3064
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3124
3125
3126
3127
3128
3129
3130
3131
3134
3135
3136
3137
3138
3139
3140
3141
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
3174
3175
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3258 if (!iface && typeId != QMetaType::UnknownType)
3259 qWarning(
"Trying to construct an instance of an invalid type, type id: %i", typeId);
3265
3266
3267
3268
3269
3272
3273
3274
3276
3277QMetaType::QMetaType(
int typeId) : QMetaType(interfaceForType(typeId)) {}
3281
3282
3283
3284
3285
3287namespace QtPrivate {
3288#if !defined(QT_BOOTSTRAPPED) && !defined(Q_CC_MSVC) && !defined(Q_OS_INTEGRITY)
3291#define QT_METATYPE_DECLARE_TEMPLATE_ITER(TypeName, Id, Name)
3292 template class QMetaTypeForType<Name>;
3293 template struct QMetaTypeInterfaceWrapper<Name>;
3300#undef QT_METATYPE_DECLARE_TEMPLATE_ITER
The QAssociativeIterable class is an iterable interface for an associative container in a QVariant.
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
The QSequentialIterable class is an iterable interface for a container in a QVariant.
QList< QVariant > QVariantList