QtBase  v6.3.1
qvariant.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2021 The Qt Company Ltd.
4 ** Copyright (C) 2021 Intel Corporation.
5 ** Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>
6 ** Contact: https://www.qt.io/licensing/
7 **
8 ** This file is part of the QtCore module of the Qt Toolkit.
9 **
10 ** $QT_BEGIN_LICENSE:LGPL$
11 ** Commercial License Usage
12 ** Licensees holding valid commercial Qt licenses may use this file in
13 ** accordance with the commercial license agreement provided with the
14 ** Software or, alternatively, in accordance with the terms contained in
15 ** a written agreement between you and The Qt Company. For licensing terms
16 ** and conditions see https://www.qt.io/terms-conditions. For further
17 ** information use the contact form at https://www.qt.io/contact-us.
18 **
19 ** GNU Lesser General Public License Usage
20 ** Alternatively, this file may be used under the terms of the GNU Lesser
21 ** General Public License version 3 as published by the Free Software
22 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
23 ** packaging of this file. Please review the following information to
24 ** ensure the GNU Lesser General Public License version 3 requirements
25 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
26 **
27 ** GNU General Public License Usage
28 ** Alternatively, this file may be used under the terms of the GNU
29 ** General Public License version 2.0 or (at your option) the GNU General
30 ** Public license version 3 or any later version approved by the KDE Free
31 ** Qt Foundation. The licenses are as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
33 ** included in the packaging of this file. Please review the following
34 ** information to ensure the GNU General Public License requirements will
35 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
36 ** https://www.gnu.org/licenses/gpl-3.0.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qvariant.h"
43 #include "qbitarray.h"
44 #include "qbytearray.h"
45 #include "qdatastream.h"
46 #include "qdebug.h"
47 #include "qmap.h"
48 #include "qdatetime.h"
49 #if QT_CONFIG(easingcurve)
50 #include "qeasingcurve.h"
51 #endif
52 #include "qlist.h"
53 #if QT_CONFIG(regularexpression)
54 #include "qregularexpression.h"
55 #endif
56 #include "qstring.h"
57 #include "qstringlist.h"
58 #include "qurl.h"
59 #include "qlocale.h"
60 #include "quuid.h"
61 #if QT_CONFIG(itemmodel)
62 #include "qabstractitemmodel.h"
63 #endif
64 #ifndef QT_BOOTSTRAPPED
65 #include "qcborarray.h"
66 #include "qcborcommon.h"
67 #include "qcbormap.h"
68 #include "qjsonvalue.h"
69 #include "qjsonobject.h"
70 #include "qjsonarray.h"
71 #include "qjsondocument.h"
72 #include "qbytearraylist.h"
73 #endif
74 #include "private/qvariant_p.h"
75 #include "private/qlocale_p.h"
76 #include "qmetatype_p.h"
77 #include <qmetaobject.h>
78 
79 #ifndef QT_NO_GEOM_VARIANT
80 #include "qsize.h"
81 #include "qpoint.h"
82 #include "qrect.h"
83 #include "qline.h"
84 #endif
85 
86 #include <cmath>
87 #include <float.h>
88 #include <cstring>
89 
91 
92 namespace { // anonymous used to hide QVariant handlers
93 
97 static qlonglong qMetaTypeNumber(const QVariant::Private *d)
98 {
99  switch (d->typeId()) {
100  case QMetaType::Int:
101  return d->get<int>();
102  case QMetaType::LongLong:
103  return d->get<qlonglong>();
104  case QMetaType::Char:
105  return qlonglong(d->get<char>());
106  case QMetaType::SChar:
107  return qlonglong(d->get<signed char>());
108  case QMetaType::Short:
109  return qlonglong(d->get<short>());
110  case QMetaType::Long:
111  return qlonglong(d->get<long>());
112  case QMetaType::Float:
113  return qRound64(d->get<float>());
114  case QMetaType::Double:
115  return qRound64(d->get<double>());
116 #ifndef QT_BOOTSTRAPPED
117  case QMetaType::QJsonValue:
118  return d->get<QJsonValue>().toDouble();
120  return d->get<QCborValue>().toInteger();
121 #endif
122  }
123  Q_ASSERT(false);
124  return 0;
125 }
126 
127 static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
128 {
129  switch (d->typeId()) {
130  case QMetaType::UInt:
131  return d->get<unsigned int>();
132  case QMetaType::ULongLong:
133  return d->get<qulonglong>();
134  case QMetaType::UChar:
135  return d->get<unsigned char>();
136  case QMetaType::UShort:
137  return d->get<unsigned short>();
138  case QMetaType::ULong:
139  return d->get<unsigned long>();
140  }
141  Q_ASSERT(false);
142  return 0;
143 }
144 
145 static qlonglong qConvertToNumber(const QVariant::Private *d, bool *ok, bool allowStringToBool = false)
146 {
147  *ok = true;
148 
149  switch (uint(d->typeId())) {
150  case QMetaType::QString: {
151  const QString &s = d->get<QString>();
152  qlonglong l = s.toLongLong(ok);
153  if (*ok)
154  return l;
155  if (allowStringToBool) {
156  if (s == QLatin1String("false") || s == QLatin1String("0")) {
157  *ok = true;
158  return 0;
159  }
160  if (s == QLatin1String("true") || s == QLatin1String("1")) {
161  *ok = true;
162  return 1;
163  }
164  }
165  return 0;
166  }
167  case QMetaType::QChar:
168  return d->get<QChar>().unicode();
170  return d->get<QByteArray>().toLongLong(ok);
171  case QMetaType::Bool:
172  return qlonglong(d->get<bool>());
173 #ifndef QT_BOOTSTRAPPED
175  if (!d->get<QCborValue>().isInteger() && !d->get<QCborValue>().isDouble())
176  break;
177  return qMetaTypeNumber(d);
178  case QMetaType::QJsonValue:
179  if (!d->get<QJsonValue>().isDouble())
180  break;
181  Q_FALLTHROUGH();
182 #endif
183  case QMetaType::Double:
184  case QMetaType::Int:
185  case QMetaType::Char:
186  case QMetaType::SChar:
187  case QMetaType::Short:
188  case QMetaType::Long:
189  case QMetaType::Float:
190  case QMetaType::LongLong:
191  return qMetaTypeNumber(d);
192  case QMetaType::ULongLong:
193  case QMetaType::UInt:
194  case QMetaType::UChar:
195  case QMetaType::UShort:
196  case QMetaType::ULong:
197 
198  return qlonglong(qMetaTypeUNumber(d));
199  }
200 
201  QMetaType typeInfo = d->type();
202  if (typeInfo.flags() & QMetaType::IsEnumeration
203  || d->typeId() == QMetaType::QCborSimpleType) {
204  switch (typeInfo.sizeOf()) {
205  case 1:
206  return d->get<signed char>();
207  case 2:
208  return d->get<short>();
209  case 4:
210  return d->get<int>();
211  case 8:
212  return d->get<qlonglong>();
213  }
214  }
215 
216  *ok = false;
217  return Q_INT64_C(0);
218 }
219 
220 static qreal qConvertToRealNumber(const QVariant::Private *d, bool *ok)
221 {
222  *ok = true;
223  switch (uint(d->typeId())) {
224  case QMetaType::QString:
225  return d->get<QString>().toDouble(ok);
226  case QMetaType::Double:
227  return qreal(d->get<double>());
228  case QMetaType::Float:
229  return qreal(d->get<float>());
230  case QMetaType::ULongLong:
231  case QMetaType::UInt:
232  case QMetaType::UChar:
233  case QMetaType::UShort:
234  case QMetaType::ULong:
235  return qreal(qMetaTypeUNumber(d));
236 #ifndef QT_BOOTSTRAPPED
238  return d->get<QCborValue>().toDouble();
239  case QMetaType::QJsonValue:
240  return d->get<QJsonValue>().toDouble();
241 #endif
242  default:
243  // includes enum conversion as well as invalid types
244  return qreal(qConvertToNumber(d, ok));
245  }
246 }
247 
248 // the type of d has already been set, but other field are not set
249 static void customConstruct(QVariant::Private *d, const void *copy)
250 {
251  QtPrivate::QMetaTypeInterface *iface = d->typeInterface();
252  if (!(iface && iface->size)) {
253  *d = QVariant::Private();
254  return;
255  }
256 
258  // QVariant requires type to be copy and default constructible
259  Q_ASSERT(iface->copyCtr);
260  Q_ASSERT(iface->defaultCtr);
261  if (copy)
262  iface->copyCtr(iface, &d->data, copy);
263  else
264  iface->defaultCtr(iface, &d->data);
265  d->is_shared = false;
266  } else {
267  d->data.shared = QVariant::PrivateShared::create(iface);
268  if (copy)
269  iface->copyCtr(iface, d->data.shared->data(), copy);
270  else
271  iface->defaultCtr(iface, d->data.shared->data());
272  d->is_shared = true;
273  }
274  // need to check for nullptr_t here, as this can get called by fromValue(nullptr). fromValue() uses
275  // std::addressof(value) which in this case returns the address of the nullptr object.
276  d->is_null = !copy || QMetaType(iface) == QMetaType::fromType<std::nullptr_t>();
277 }
278 
279 static void customClear(QVariant::Private *d)
280 {
281  auto iface = reinterpret_cast<QtPrivate::QMetaTypeInterface *>(d->packedType << 2);
282  if (!iface)
283  return;
284  if (!d->is_shared) {
285  if (iface->dtor)
286  iface->dtor(iface, &d->data);
287  } else {
288  if (iface->dtor)
289  iface->dtor(iface, d->data.shared->data());
290  QVariant::PrivateShared::free(d->data.shared);
291  }
292 }
293 
294 
295 } // anonymous used to hide QVariant handlers
296 
483 //### Qt 7: Remove in favor of QMetaType overload
484 void QVariant::create(int type, const void *copy)
485 {
486  create(QMetaType(type), copy);
487 }
488 
495 void QVariant::create(QMetaType type, const void *copy)
496 {
497  d = Private(type);
498  customConstruct(&d, copy);
499 }
500 
513 {
514  if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared))
515  customClear(&d);
516 }
517 
526  : d(p.d)
527 {
528  if (d.is_shared) {
529  d.data.shared->ref.ref();
530  return;
531  }
533  auto other = p.constData();
534  if (iface) {
535  if (other)
536  iface->copyCtr(iface, &d.data, other);
537  else
538  iface->defaultCtr(iface, &d.data);
539  }
540 }
541 
819 QVariant::QVariant(QMetaType type, const void *copy) : d(type)
820 {
821  customConstruct(&d, copy);
822 }
823 
825  : d(QMetaType::fromType<int>())
826 { d.set(val); }
828  : d(QMetaType::fromType<uint>())
829 { d.set(val); }
831  : d(QMetaType::fromType<qlonglong>())
832 { d.set(val); }
834  : d(QMetaType::fromType<qulonglong>())
835 { d.set(val); }
837  : d(QMetaType::fromType<bool>())
838 { d.set(val); }
840  : d(QMetaType::fromType<double>())
841 { d.set(val); }
843  : d(QMetaType::fromType<float>())
844 { d.set(val); }
845 
847  : d(QMetaType::fromType<QByteArray>())
848 { v_construct<QByteArray>(&d, val); }
850  : d(QMetaType::fromType<QBitArray>())
851 { v_construct<QBitArray>(&d, val); }
853  : d(QMetaType::fromType<QString>())
854 { v_construct<QString>(&d, val); }
856  : d(QMetaType::fromType<QChar>())
857 { v_construct<QChar>(&d, val); }
859  : d(QMetaType::fromType<QString>())
860 { v_construct<QString>(&d, val); }
862  : d(QMetaType::fromType<QStringList>())
863 { v_construct<QStringList>(&d, val); }
864 
866  : d(QMetaType::fromType<QDate>())
867 { v_construct<QDate>(&d, val); }
869  : d(QMetaType::fromType<QTime>())
870 { v_construct<QTime>(&d, val); }
872  : d(QMetaType::fromType<QDateTime>())
873 { v_construct<QDateTime>(&d, val); }
874 #if QT_CONFIG(easingcurve)
876  : d(QMetaType::fromType<QEasingCurve>())
877 { v_construct<QEasingCurve>(&d, val); }
878 #endif
880  : d(QMetaType::fromType<QList<QVariant>>())
881 { v_construct<QVariantList>(&d, list); }
883  : d(QMetaType::fromType<QMap<QString, QVariant>>())
884 { v_construct<QVariantMap>(&d, map); }
886  : d(QMetaType::fromType<QHash<QString, QVariant>>())
887 { v_construct<QVariantHash>(&d, hash); }
888 #ifndef QT_NO_GEOM_VARIANT
890  : d(QMetaType::fromType<QPoint>())
891 { v_construct<QPoint>(&d, pt); }
893  : d(QMetaType::fromType<QPointF>())
894 { v_construct<QPointF>(&d, pt); }
896  : d(QMetaType::fromType<QRectF>())
897 { v_construct<QRectF>(&d, r); }
899  : d(QMetaType::fromType<QLineF>())
900 { v_construct<QLineF>(&d, l); }
902  : d(QMetaType::fromType<QLine>())
903 { v_construct<QLine>(&d, l); }
905  : d(QMetaType::fromType<QRect>())
906 { v_construct<QRect>(&d, r); }
908  : d(QMetaType::fromType<QSize>())
909 { v_construct<QSize>(&d, s); }
911  : d(QMetaType::fromType<QSizeF>())
912 { v_construct<QSizeF>(&d, s); }
913 #endif
914 #ifndef QT_BOOTSTRAPPED
916  : d(QMetaType::fromType<QUrl>())
917 { v_construct<QUrl>(&d, u); }
918 #endif
920  : d(QMetaType::fromType<QLocale>())
921 { v_construct<QLocale>(&d, l); }
922 #if QT_CONFIG(regularexpression)
924  : d(QMetaType::fromType<QRegularExpression>())
925 { v_construct<QRegularExpression>(&d, re); }
926 #endif // QT_CONFIG(regularexpression)
928  : d(QMetaType::fromType<QUuid>())
929 { v_construct<QUuid>(&d, uuid); }
930 #ifndef QT_BOOTSTRAPPED
932  : d(QMetaType::fromType<QJsonValue>())
933 { v_construct<QJsonValue>(&d, jsonValue); }
934 QVariant::QVariant(const QJsonObject &jsonObject)
935  : d(QMetaType::fromType<QJsonObject>())
936 { v_construct<QJsonObject>(&d, jsonObject); }
938  : d(QMetaType::fromType<QJsonArray>())
939 { v_construct<QJsonArray>(&d, jsonArray); }
940 QVariant::QVariant(const QJsonDocument &jsonDocument)
941  : d(QMetaType::fromType<QJsonDocument>())
942 { v_construct<QJsonDocument>(&d, jsonDocument); }
943 #endif // QT_BOOTSTRAPPED
944 #if QT_CONFIG(itemmodel)
945 QVariant::QVariant(const QModelIndex &modelIndex)
946  : d(QMetaType::fromType<QModelIndex>())
947 { v_construct<QModelIndex>(&d, modelIndex); }
948 QVariant::QVariant(const QPersistentModelIndex &modelIndex)
949  : d(QMetaType::fromType<QPersistentModelIndex>())
950 { v_construct<QPersistentModelIndex>(&d, modelIndex); }
951 #endif
952 
1004 {
1005  return d.type();
1006 }
1007 
1012 {
1013  if (this == &variant)
1014  return *this;
1015 
1016  clear();
1017  if (variant.d.is_shared) {
1018  variant.d.data.shared->ref.ref();
1019  d = variant.d;
1020  } else {
1021  d = variant.d;
1023  const void *other = variant.constData();
1024  if (iface) {
1025  if (other)
1026  iface->copyCtr(iface, &d, other);
1027  else
1028  iface->defaultCtr(iface, &d);
1029  }
1030  }
1031 
1032  return *this;
1033 }
1034 
1050 {
1051  if (!d.is_shared || d.data.shared->ref.loadRelaxed() == 1)
1052  return;
1053 
1054  Private dd(d.type());
1055  customConstruct(&dd, constData());
1056  if (!d.data.shared->ref.deref())
1057  customClear(&d);
1058  d.data.shared = dd.data.shared;
1059 }
1060 
1073 const char *QVariant::typeName() const
1074 {
1075  return d.type().name();
1076 }
1077 
1083 {
1084  if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared))
1085  customClear(&d);
1086  d = {};
1087 }
1088 
1110 #ifndef QT_NO_DATASTREAM
1111 enum { MapFromThreeCount = 36 };
1112 static const ushort mapIdFromQt3ToCurrent[MapFromThreeCount] =
1113 {
1119  QMetaType::QFont,
1120  QMetaType::QPixmap,
1121  QMetaType::QBrush,
1122  QMetaType::QRect,
1123  QMetaType::QSize,
1124  QMetaType::QColor,
1125  QMetaType::QPalette,
1126  0, // ColorGroup
1127  QMetaType::QIcon,
1128  QMetaType::QPoint,
1129  QMetaType::QImage,
1134  0, // Buggy ByteArray, QByteArray never had id == 20
1135  QMetaType::QPolygon,
1136  QMetaType::QRegion,
1137  QMetaType::QBitmap,
1138  QMetaType::QCursor,
1139  QMetaType::QSizePolicy,
1140  QMetaType::QDate,
1141  QMetaType::QTime,
1142  QMetaType::QDateTime,
1145 #if QT_CONFIG(shortcut)
1146  QMetaType::QKeySequence,
1147 #else
1148  0, // QKeySequence
1149 #endif
1150  QMetaType::QPen,
1151  QMetaType::LongLong,
1152  QMetaType::ULongLong,
1153 #if QT_CONFIG(easingcurve)
1154  QMetaType::QEasingCurve
1155 #endif
1156 };
1157 
1158 // values needed to map Qt5 based type id's to Qt6 based ones
1159 constexpr int Qt5UserType = 1024;
1160 constexpr int Qt5LastCoreType = QMetaType::QCborMap;
1161 constexpr int Qt5FirstGuiType = 64;
1162 constexpr int Qt5LastGuiType = 87;
1163 constexpr int Qt5SizePolicy = 121;
1164 constexpr int Qt5RegExp = 27;
1165 constexpr int Qt5KeySequence = 75;
1166 constexpr int Qt5QQuaternion = 85;
1167 
1169 
1177 {
1178  clear();
1179 
1180  quint32 typeId;
1181  s >> typeId;
1182  if (s.version() < QDataStream::Qt_4_0) {
1183  // map to Qt 5 ids
1184  if (typeId >= MapFromThreeCount)
1185  return;
1186  typeId = mapIdFromQt3ToCurrent[typeId];
1187  } else if (s.version() < QDataStream::Qt_5_0) {
1188  // map to Qt 5 type ids
1189  if (typeId == 127 /* QVariant::UserType */) {
1190  typeId = Qt5UserType;
1191  } else if (typeId >= 128 && typeId != Qt5UserType) {
1192  // In Qt4 id == 128 was FirstExtCoreType. In Qt5 ExtCoreTypes set was merged to CoreTypes
1193  // by moving all ids down by 97.
1194  typeId -= 97;
1195  } else if (typeId == 75 /* QSizePolicy */) {
1197  } else if (typeId > 75 && typeId <= 86) {
1198  // and as a result these types received lower ids too
1199  // QKeySequence QPen QTextLength QTextFormat QTransform QMatrix4x4 QVector2D QVector3D QVector4D QQuaternion
1200  typeId -=1;
1201  }
1202  }
1203  if (s.version() < QDataStream::Qt_6_0) {
1204  // map from Qt 5 to Qt 6 values
1205  if (typeId == Qt5UserType) {
1207  } else if (typeId >= Qt5FirstGuiType && typeId <= Qt5LastGuiType) {
1209  } else if (typeId == Qt5SizePolicy) {
1210  typeId = QMetaType::QSizePolicy;
1211  } else if (typeId == Qt5RegExp) {
1212  typeId = QMetaType::fromName("QRegExp").id();
1213  }
1214  }
1215 
1216  qint8 is_null = false;
1217  if (s.version() >= QDataStream::Qt_4_2)
1218  s >> is_null;
1219  if (typeId == QMetaType::User) {
1220  QByteArray name;
1221  s >> name;
1223  if (typeId == QMetaType::UnknownType) {
1224  s.setStatus(QDataStream::ReadCorruptData);
1225  qWarning("QVariant::load: unknown user type with name %s.", name.constData());
1226  return;
1227  }
1228  }
1229  create(typeId, nullptr);
1230  d.is_null = is_null;
1231 
1232  if (!isValid()) {
1233  if (s.version() < QDataStream::Qt_5_0) {
1234  // Since we wrote something, we should read something
1235  QString x;
1236  s >> x;
1237  }
1238  d.is_null = true;
1239  return;
1240  }
1241 
1242  // const cast is safe since we operate on a newly constructed variant
1243  void *data = const_cast<void *>(constData());
1244  if (!d.type().load(s, data)) {
1245  s.setStatus(QDataStream::ReadCorruptData);
1246  qWarning("QVariant::load: unable to load type %d.", d.typeId());
1247  }
1248 }
1249 
1257 {
1258  quint32 typeId = d.typeId();
1259  bool saveAsUserType = false;
1260  if (typeId >= QMetaType::User) {
1262  saveAsUserType = true;
1263  }
1264  if (s.version() < QDataStream::Qt_6_0) {
1265  // map to Qt 5 values
1266  if (typeId == QMetaType::User) {
1267  typeId = Qt5UserType;
1268  if (!strcmp(d.type().name(), "QRegExp")) {
1269  typeId = 27; // QRegExp in Qt 4/5
1270  }
1272  // the type didn't exist in Qt 5
1273  typeId = Qt5UserType;
1274  saveAsUserType = true;
1277  if (typeId > Qt5LastGuiType) {
1278  typeId = Qt5UserType;
1279  saveAsUserType = true;
1280  }
1281  } else if (typeId == QMetaType::QSizePolicy) {
1283  }
1284  }
1285  if (s.version() < QDataStream::Qt_4_0) {
1286  int i;
1287  for (i = 0; i <= MapFromThreeCount - 1; ++i) {
1288  if (mapIdFromQt3ToCurrent[i] == typeId) {
1289  typeId = i;
1290  break;
1291  }
1292  }
1293  if (i >= MapFromThreeCount) {
1294  s << QVariant();
1295  return;
1296  }
1297  } else if (s.version() < QDataStream::Qt_5_0) {
1298  if (typeId == Qt5UserType) {
1299  typeId = 127; // QVariant::UserType had this value in Qt4
1300  saveAsUserType = true;
1301  } else if (typeId >= 128 - 97 && typeId <= Qt5LastCoreType) {
1302  // In Qt4 id == 128 was FirstExtCoreType. In Qt5 ExtCoreTypes set was merged to CoreTypes
1303  // by moving all ids down by 97.
1304  typeId += 97;
1305  } else if (typeId == Qt5SizePolicy) {
1306  typeId = 75;
1307  } else if (typeId >= Qt5KeySequence && typeId <= Qt5QQuaternion) {
1308  // and as a result these types received lower ids too
1309  typeId += 1;
1310  } else if (typeId > Qt5QQuaternion || typeId == QMetaType::QUuid) {
1311  // These existed in Qt 4 only as a custom type
1312  typeId = 127;
1313  saveAsUserType = true;
1314  }
1315  }
1316  const char *typeName = nullptr;
1317  if (saveAsUserType) {
1318  if (s.version() < QDataStream::Qt_6_0)
1320  if (!typeName)
1321  typeName = d.type().name();
1322  }
1323  s << typeId;
1324  if (s.version() >= QDataStream::Qt_4_2)
1325  s << qint8(d.is_null);
1326  if (typeName)
1327  s << typeName;
1328 
1329  if (!isValid()) {
1330  if (s.version() < QDataStream::Qt_5_0)
1331  s << QString();
1332  return;
1333  }
1334 
1335  if (!d.type().save(s, constData())) {
1336  qWarning("QVariant::save: unable to save type '%s' (type id: %d).\n",
1337  d.type().name(), d.typeId());
1338  Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
1339  }
1340 }
1341 
1350 {
1351  p.load(s);
1352  return s;
1353 }
1354 
1361 {
1362  p.save(s);
1363  return s;
1364 }
1365 
1377 #endif //QT_NO_DATASTREAM
1378 
1397 {
1398  return qvariant_cast<QStringList>(*this);
1399 }
1400 
1417 {
1418  return qvariant_cast<QString>(*this);
1419 }
1420 
1428 {
1429  return qvariant_cast<QVariantMap>(*this);
1430 }
1431 
1439 {
1440  return qvariant_cast<QVariantHash>(*this);
1441 }
1442 
1456 {
1457  return qvariant_cast<QDate>(*this);
1458 }
1459 
1473 {
1474  return qvariant_cast<QTime>(*this);
1475 }
1476 
1490 {
1491  return qvariant_cast<QDateTime>(*this);
1492 }
1493 
1503 #if QT_CONFIG(easingcurve)
1504 QEasingCurve QVariant::toEasingCurve() const
1505 {
1506  return qvariant_cast<QEasingCurve>(*this);
1507 }
1508 #endif
1509 
1520 {
1521  return qvariant_cast<QByteArray>(*this);
1522 }
1523 
1524 #ifndef QT_NO_GEOM_VARIANT
1535 {
1536  return qvariant_cast<QPoint>(*this);
1537 }
1538 
1548 {
1549  return qvariant_cast<QRect>(*this);
1550 }
1551 
1561 {
1562  return qvariant_cast<QSize>(*this);
1563 }
1564 
1574 {
1575  return qvariant_cast<QSizeF>(*this);
1576 }
1577 
1588 {
1589  return qvariant_cast<QRectF>(*this);
1590 }
1591 
1601 {
1602  return qvariant_cast<QLineF>(*this);
1603 }
1604 
1614 {
1615  return qvariant_cast<QLine>(*this);
1616 }
1617 
1628 {
1629  return qvariant_cast<QPointF>(*this);
1630 }
1631 
1632 #endif // QT_NO_GEOM_VARIANT
1633 
1634 #ifndef QT_BOOTSTRAPPED
1644 {
1645  return qvariant_cast<QUrl>(*this);
1646 }
1647 #endif
1648 
1658 {
1659  return qvariant_cast<QLocale>(*this);
1660 }
1661 
1662 #if QT_CONFIG(regularexpression)
1672 QRegularExpression QVariant::toRegularExpression() const
1673 {
1674  return qvariant_cast<QRegularExpression>(*this);
1675 }
1676 #endif // QT_CONFIG(regularexpression)
1677 
1678 #if QT_CONFIG(itemmodel)
1687 QModelIndex QVariant::toModelIndex() const
1688 {
1689  return qvariant_cast<QModelIndex>(*this);
1690 }
1691 
1700 QPersistentModelIndex QVariant::toPersistentModelIndex() const
1701 {
1702  return qvariant_cast<QPersistentModelIndex>(*this);
1703 }
1704 #endif // QT_CONFIG(itemmodel)
1705 
1716 {
1717  return qvariant_cast<QUuid>(*this);
1718 }
1719 
1720 #ifndef QT_BOOTSTRAPPED
1730 {
1731  return qvariant_cast<QJsonValue>(*this);
1732 }
1733 
1743 {
1744  return qvariant_cast<QJsonObject>(*this);
1745 }
1746 
1756 {
1757  return qvariant_cast<QJsonArray>(*this);
1758 }
1759 
1769 {
1770  return qvariant_cast<QJsonDocument>(*this);
1771 }
1772 #endif // QT_BOOTSTRAPPED
1773 
1784 {
1785  return qvariant_cast<QChar>(*this);
1786 }
1787 
1795 {
1796  return qvariant_cast<QBitArray>(*this);
1797 }
1798 
1799 template <typename T>
1800 inline T qNumVariantToHelper(const QVariant::Private &d, bool *ok, const T& val)
1801 {
1802  QMetaType t = QMetaType::fromType<T>();
1803  if (ok)
1804  *ok = true;
1805 
1806  if (d.type() == t)
1807  return val;
1808 
1809  T ret = 0;
1810  bool success = QMetaType::convert(d.type(), d.storage(), t, &ret);
1811  if (ok)
1812  *ok = success;
1813  return ret;
1814 }
1815 
1833 int QVariant::toInt(bool *ok) const
1834 {
1835  return qNumVariantToHelper<int>(d, ok, d.get<int>());
1836 }
1837 
1856 {
1857  return qNumVariantToHelper<uint>(d, ok, d.get<unsigned int>());
1858 }
1859 
1873 {
1874  return qNumVariantToHelper<qlonglong>(d, ok, d.get<qlonglong>());
1875 }
1876 
1890 {
1891  return qNumVariantToHelper<qulonglong>(d, ok, d.get<qulonglong>());
1892 }
1893 
1906 bool QVariant::toBool() const
1907 {
1908  auto boolType = QMetaType::fromType<bool>();
1909  if (d.type() == boolType)
1910  return d.get<bool>();
1911 
1912  bool res = false;
1913  QMetaType::convert(d.type(), constData(), boolType, &res);
1914  return res;
1915 }
1916 
1929 double QVariant::toDouble(bool *ok) const
1930 {
1931  return qNumVariantToHelper<double>(d, ok, d.get<double>());
1932 }
1933 
1948 float QVariant::toFloat(bool *ok) const
1949 {
1950  return qNumVariantToHelper<float>(d, ok, d.get<float>());
1951 }
1952 
1968 {
1969  return qNumVariantToHelper<qreal>(d, ok, d.get<qreal>());
1970 }
1971 
1980 {
1981  return qvariant_cast<QVariantList>(*this);
1982 }
1983 
2050 {
2051  if (d.type() == targetType)
2052  return targetType.isValid();
2053 
2054  QVariant oldValue = *this;
2055 
2056  clear();
2057  create(targetType, nullptr);
2058  if (!oldValue.canConvert(targetType))
2059  return false;
2060 
2061  // Fail if the value is not initialized or was forced null by a previous failed convert.
2062  if (oldValue.d.is_null && oldValue.d.typeId() != QMetaType::Nullptr)
2063  return false;
2064 
2065  bool ok = QMetaType::convert(oldValue.d.type(), oldValue.constData(), targetType, data());
2066  d.is_null = !ok;
2067  return ok;
2068 }
2069 
2075 bool QVariant::convert(int type, void *ptr) const
2076 {
2077  return QMetaType::convert(d.type(), constData(), QMetaType(type), ptr);
2078 }
2079 
2083 bool QVariant::view(int type, void *ptr)
2084 {
2085  return QMetaType::view(d.type(), data(), QMetaType(type), ptr);
2086 }
2087 
2136 static bool qIsNumericType(uint tp)
2137 {
2138  static const qulonglong numericTypeBits =
2140  Q_UINT64_C(1) << QMetaType::Bool |
2143  Q_UINT64_C(1) << QMetaType::Char |
2144  Q_UINT64_C(1) << QMetaType::SChar |
2145  Q_UINT64_C(1) << QMetaType::UChar |
2148  Q_UINT64_C(1) << QMetaType::Int |
2149  Q_UINT64_C(1) << QMetaType::UInt |
2150  Q_UINT64_C(1) << QMetaType::Long |
2152  Q_UINT64_C(1) << QMetaType::LongLong |
2153  Q_UINT64_C(1) << QMetaType::ULongLong;
2154  return tp < (CHAR_BIT * sizeof numericTypeBits) ? numericTypeBits & (Q_UINT64_C(1) << tp) : false;
2155 }
2156 
2157 static bool qIsFloatingPoint(uint tp)
2158 {
2159  return tp == QMetaType::Double || tp == QMetaType::Float;
2160 }
2161 
2162 static int normalizeLowerRanks(uint tp)
2163 {
2164  static const qulonglong numericTypeBits =
2165  Q_UINT64_C(1) << QMetaType::Bool |
2166  Q_UINT64_C(1) << QMetaType::Char |
2167  Q_UINT64_C(1) << QMetaType::SChar |
2168  Q_UINT64_C(1) << QMetaType::UChar |
2171  return numericTypeBits & (Q_UINT64_C(1) << tp) ? uint(QMetaType::Int) : tp;
2172 }
2173 
2174 static int normalizeLong(uint tp)
2175 {
2176  const uint IntType = sizeof(long) == sizeof(int) ? QMetaType::Int : QMetaType::LongLong;
2177  const uint UIntType = sizeof(ulong) == sizeof(uint) ? QMetaType::UInt : QMetaType::ULongLong;
2178  return tp == QMetaType::Long ? IntType :
2179  tp == QMetaType::ULong ? UIntType : tp;
2180 }
2181 
2182 static int numericTypePromotion(uint t1, uint t2)
2183 {
2184  Q_ASSERT(qIsNumericType(t1));
2185  Q_ASSERT(qIsNumericType(t2));
2186 
2187  if ((t1 == QMetaType::Bool && t2 == QMetaType::QString) ||
2189  return QMetaType::Bool;
2190 
2191  // C++ integral ranks: (4.13 Integer conversion rank [conv.rank])
2192  // bool < signed char < short < int < long < long long
2193  // unsigneds have the same rank as their signed counterparts
2194  // C++ integral promotion rules (4.5 Integral Promotions [conv.prom])
2195  // - any type with rank less than int can be converted to int or unsigned int
2196  // 5 Expressions [expr] paragraph 9:
2197  // - if either operand is double, the other shall be converted to double
2198  // - " " float, " " " float
2199  // - if both operands have the same type, no further conversion is needed.
2200  // - if both are signed or if both are unsigned, convert to the one with highest rank
2201  // - if the unsigned has higher or same rank, convert the signed to the unsigned one
2202  // - if the signed can represent all values of the unsigned, convert to the signed
2203  // - otherwise, convert to the unsigned corresponding to the rank of the signed
2204 
2205  // floating point: we deviate from the C++ standard by always using qreal
2206  if (qIsFloatingPoint(t1) || qIsFloatingPoint(t2))
2207  return QMetaType::QReal;
2208 
2209  // integral rules:
2210  // for all platforms we support, int can always hold the values of lower-ranked types
2211  t1 = normalizeLowerRanks(t1);
2212  t2 = normalizeLowerRanks(t2);
2213 
2214  // normalize long / ulong: in all platforms we run, they're either the same as int or as long long
2215  t1 = normalizeLong(t1);
2216  t2 = normalizeLong(t2);
2217 
2218  // implement the other rules
2219  // the four possibilities are Int, UInt, LongLong and ULongLong
2220  // if any of the two is ULongLong, then it wins (highest rank, unsigned)
2221  // otherwise, if one of the two is LongLong, then the other is either LongLong too or lower-ranked
2222  // otherwise, if one of the two is UInt, then the other is either UInt too or Int
2223  if (t1 == QMetaType::ULongLong || t2 == QMetaType::ULongLong)
2224  return QMetaType::ULongLong;
2225  if (t1 == QMetaType::LongLong || t2 == QMetaType::LongLong)
2226  return QMetaType::LongLong;
2227  if (t1 == QMetaType::UInt || t2 == QMetaType::UInt)
2228  return QMetaType::UInt;
2229  return QMetaType::Int;
2230 }
2231 
2232 static bool integralEquals(uint promotedType, const QVariant::Private *d1, const QVariant::Private *d2)
2233 {
2234  // use toLongLong to retrieve the data, it gets us all the bits
2235  bool ok;
2236  qlonglong l1 = qConvertToNumber(d1, &ok, promotedType == QMetaType::Bool);
2237  if (!ok)
2238  return false;
2239 
2240  qlonglong l2 = qConvertToNumber(d2, &ok, promotedType == QMetaType::Bool);
2241  if (!ok)
2242  return false;
2243 
2244  if (promotedType == QMetaType::Bool)
2245  return bool(l1) == bool(l2);
2246  if (promotedType == QMetaType::Int)
2247  return int(l1) == int(l2);
2248  if (promotedType == QMetaType::UInt)
2249  return uint(l1) == uint(l2);
2250  if (promotedType == QMetaType::LongLong)
2251  return l1 == l2;
2252  if (promotedType == QMetaType::ULongLong)
2253  return qulonglong(l1) == qulonglong(l2);
2254 
2255  Q_UNREACHABLE();
2256  return 0;
2257 }
2258 
2259 namespace {
2260 template<typename Numeric>
2261 int spaceShip(Numeric lhs, Numeric rhs)
2262 {
2263  bool smaller;
2264  if constexpr (std::is_same_v<Numeric, QObject *>)
2265  smaller = std::less<QObject *>()(lhs, rhs); // can't use less all the time because of bool
2266  else
2267  smaller = lhs < rhs;
2268  if (smaller)
2269  return -1;
2270  else if (lhs == rhs)
2271  return 0;
2272  else
2273  return 1;
2274 }
2275 }
2276 
2277 static std::optional<int> integralCompare(uint promotedType, const QVariant::Private *d1, const QVariant::Private *d2)
2278 {
2279  // use toLongLong to retrieve the data, it gets us all the bits
2280  bool ok;
2281  qlonglong l1 = qConvertToNumber(d1, &ok, promotedType == QMetaType::Bool);
2282  if (!ok)
2283  return std::nullopt;
2284 
2285  qlonglong l2 = qConvertToNumber(d2, &ok, promotedType == QMetaType::Bool);
2286  if (!ok)
2287  return std::nullopt;
2288 
2289  if (promotedType == QMetaType::Bool)
2290  return spaceShip<bool>(l1, l2);
2291  if (promotedType == QMetaType::Int)
2292  return spaceShip<int>(l1, l2);
2293  if (promotedType == QMetaType::UInt)
2294  return spaceShip<uint>(l1, l2);
2295  if (promotedType == QMetaType::LongLong)
2296  return spaceShip<qlonglong>(l1, l2);
2297  if (promotedType == QMetaType::ULongLong)
2298  return spaceShip<qulonglong>(l1, l2);
2299 
2300  Q_UNREACHABLE();
2301  return 0;
2302 }
2303 
2304 static std::optional<int> numericCompare(const QVariant::Private *d1, const QVariant::Private *d2)
2305 {
2306  uint promotedType = numericTypePromotion(d1->typeId(), d2->typeId());
2307  if (promotedType != QMetaType::QReal)
2308  return integralCompare(promotedType, d1, d2);
2309  // qreal comparisons
2310  bool ok;
2311  qreal r1 = qConvertToRealNumber(d1, &ok);
2312  if (!ok)
2313  return std::nullopt;
2314  qreal r2 = qConvertToRealNumber(d2, &ok);
2315  if (!ok)
2316  return std::nullopt;
2317  if (r1 == r2)
2318  return 0;
2319 
2320  if (std::isnan(r1) || std::isnan(r2))
2321  return std::nullopt;
2322  return spaceShip<qreal>(r1, r2);
2323 }
2324 
2325 static bool numericEquals(const QVariant::Private *d1, const QVariant::Private *d2)
2326 {
2327  uint promotedType = numericTypePromotion(d1->typeId(), d2->typeId());
2328  if (promotedType != QMetaType::QReal)
2329  return integralEquals(promotedType, d1, d2);
2330 
2331  // qreal comparisons
2332  bool ok;
2333  qreal r1 = qConvertToRealNumber(d1, &ok);
2334  if (!ok)
2335  return false;
2336  qreal r2 = qConvertToRealNumber(d2, &ok);
2337  if (!ok)
2338  return false;
2339  if (r1 == r2)
2340  return true;
2341 
2342  return false;
2343 }
2344 
2345 #ifndef QT_BOOTSTRAPPED
2346 static bool canConvertMetaObject(QMetaType fromType, QMetaType toType)
2347 {
2348  if ((fromType.flags() & QMetaType::PointerToQObject)
2349  && (toType.flags() & QMetaType::PointerToQObject)) {
2350  const QMetaObject *f = fromType.metaObject();
2351  const QMetaObject *t = toType.metaObject();
2352  return f && t && (f->inherits(t) || t->inherits(f));
2353  }
2354  return false;
2355 }
2356 
2357 static bool pointerEquals(const QVariant::Private *d1, const QVariant::Private *d2)
2358 {
2359  // simply check whether both types point to the same data
2360  return d1->get<QObject *>() == d2->get<QObject *>();
2361 }
2362 
2363 static int pointerCompare(const QVariant::Private *d1, const QVariant::Private *d2)
2364 {
2365  return spaceShip<QObject *>(d1->get<QObject *>(), d2->get<QObject *>());
2366 }
2367 #endif
2368 
2372 bool QVariant::equals(const QVariant &v) const
2373 {
2374  auto metatype = d.type();
2375 
2376  if (metatype != v.metaType()) {
2377  // try numeric comparisons, with C++ type promotion rules (no conversion)
2378  if (qIsNumericType(metatype.id()) && qIsNumericType(v.d.typeId()))
2379  return numericEquals(&d, &v.d);
2380 #ifndef QT_BOOTSTRAPPED
2381  // if both types are related pointers to QObjects, check if they point to the same object
2382  if (canConvertMetaObject(metatype, v.metaType()))
2383  return pointerEquals(&d, &v.d);
2384 #endif
2385  return false;
2386  }
2387 
2388  // For historical reasons: QVariant() == QVariant()
2389  if (!metatype.isValid())
2390  return true;
2391 
2392  return metatype.equals(d.storage(), v.d.storage());
2393 }
2394 
2395 static QPartialOrdering convertOptionalToPartialOrdering(const std::optional<int> &opt)
2396 {
2397  if (!opt)
2399  else if (*opt < 0)
2400  return QPartialOrdering::Less;
2401  else if (*opt == 0)
2403  else
2405 }
2406 
2430 {
2431  QMetaType t = lhs.d.type();
2432  if (t != rhs.d.type()) {
2433  // try numeric comparisons, with C++ type promotion rules (no conversion)
2434  if (qIsNumericType(lhs.d.typeId()) && qIsNumericType(rhs.d.typeId()))
2435  return convertOptionalToPartialOrdering(numericCompare(&lhs.d, &rhs.d));
2436 #ifndef QT_BOOTSTRAPPED
2437  if (canConvertMetaObject(lhs.metaType(), rhs.metaType()))
2438  return convertOptionalToPartialOrdering(pointerCompare(&lhs.d, &rhs.d));
2439 #endif
2441  }
2442  return t.compare(lhs.constData(), rhs.constData());
2443 }
2444 
2465 {
2466  detach();
2467  // set is_null to false, as the caller is likely to write some data into this variant
2468  d.is_null = false;
2469  return const_cast<void *>(constData());
2470 }
2471 
2483 bool QVariant::isNull() const
2484 {
2485  if (d.is_null || !metaType().isValid())
2486  return true;
2488  return d.get<void *>() == nullptr;
2489  return false;
2490 }
2491 
2492 #ifndef QT_NO_DEBUG_STREAM
2493 QDebug QVariant::qdebugHelper(QDebug dbg) const
2494 {
2495  QDebugStateSaver saver(dbg);
2496  const uint typeId = d.typeId();
2497  dbg.nospace() << "QVariant(";
2498  if (typeId != QMetaType::UnknownType) {
2499  dbg << d.type().name() << ", ";
2500  bool streamed = d.type().debugStream(dbg, d.storage());
2501  if (!streamed && canConvert<QString>())
2502  dbg << toString();
2503  } else {
2504  dbg << "Invalid";
2505  }
2506  dbg << ')';
2507  return dbg;
2508 }
2509 
2510 #if QT_DEPRECATED_SINCE(6, 0)
2513 
2515 {
2516  QDebugStateSaver saver(dbg);
2517  dbg.nospace() << "QVariant::"
2518  << (int(p) != int(QMetaType::UnknownType)
2519  ? QMetaType(p).name()
2520  : "Invalid");
2521  return dbg;
2522 }
2523 
2525 #endif
2526 
2527 #endif
2528 
2765 {
2766  if (type == QMetaType::fromType<QVariant>())
2767  return &value;
2768 
2769  if (type == value.metaType())
2770  return value.constData();
2771 
2772  if (value.canConvert(type)) {
2773  converted = value;
2774  if (converted.convert(type))
2775  return converted.constData();
2776  }
2777 
2778  return nullptr;
2779 }
2780 
2785 {
2786  if (const void *result = convert(value, type))
2787  return result;
2788 
2789  converted = QVariant(type);
2790  return converted.constData();
2791 }
2792 
2863  : m_variant(std::move(variant))
2864 {
2865 }
2866 
2871 {
2872  return m_variant;
2873 }
2874 
2880 {
2881  return &m_variant;
2882 }
2883 
small capitals from c petite p scientific f u
Definition: afcover.h:88
small capitals from c petite p scientific i
[1]
Definition: afcover.h:80
#define value
[5]
@ Float
@ Double
The QBitArray class provides an array of bits.
Definition: qbitarray.h:49
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:85
The QCborValue class encapsulates a value in CBOR.
Definition: qcborvalue.h:86
bool isDouble() const
Definition: qcborvalue.h:207
bool isInteger() const
Definition: qcborvalue.h:196
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:84
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
The QDate class provides date functions.
Definition: qdatetime.h:64
The QDateTime class provides date and time functions.
Definition: qdatetime.h:238
The QDebug class provides an output stream for debugging information.
Definition: qdebug.h:65
QDebug & nospace()
Definition: qdebug.h:113
Convenience class for custom QDebug operators.
Definition: qdebug.h:176
The QEasingCurve class provides easing curves for controlling animation.
Definition: qeasingcurve.h:55
The QJsonArray class encapsulates a JSON array.
Definition: qjsonarray.h:54
The QJsonDocument class provides a way to read and write JSON documents.
Definition: qjsondocument.h:83
The QJsonObject class encapsulates a JSON object.
Definition: qjsonobject.h:56
The QJsonValue class encapsulates a value in JSON.
Definition: qjsonvalue.h:60
bool isDouble() const
Definition: qjsonvalue.h:109
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal.
Definition: qstring.h:84
The QLineF class provides a two-dimensional vector using floating point precision.
Definition: qline.h:215
The QLine class provides a two-dimensional vector using integer precision.
Definition: qline.h:53
The QMetaType class manages named types in the meta-object system.
Definition: qmetatype.h:328
constexpr TypeFlags flags() const
Definition: qmetatype.h:2516
constexpr qsizetype sizeOf() const
Definition: qmetatype.h:2506
static bool view(QMetaType fromType, void *from, QMetaType toType, void *to)
Definition: qmetatype.cpp:2293
bool debugStream(QDebug &dbg, const void *rhs)
Definition: qmetatype.cpp:1746
static QMetaType fromName(QByteArrayView name)
Definition: qmetatype.cpp:2789
bool isValid() const
Definition: qmetatype.cpp:509
int id(int=0) const
Definition: qmetatype.h:453
@ PointerToQObject
Definition: qmetatype.h:392
@ IsEnumeration
Definition: qmetatype.h:393
@ FirstGuiType
Definition: qmetatype.h:338
@ LastCoreType
Definition: qmetatype.h:337
@ UnknownType
Definition: qmetatype.h:346
@ LastGuiType
Definition: qmetatype.h:339
constexpr const QMetaObject * metaObject() const
Definition: qmetatype.h:2521
constexpr const char * name() const
Definition: qmetatype.h:2531
bool load(QDataStream &stream, void *data) const
Definition: qmetatype.cpp:2740
bool save(QDataStream &stream, const void *data) const
Definition: qmetatype.cpp:2699
static bool convert(QMetaType fromType, const void *from, QMetaType toType, void *to)
Definition: qmetatype.cpp:2226
The QModelIndex class is used to locate data in a data model.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
static const QPartialOrdering Less
Definition: qcompare.h:75
static const QPartialOrdering Greater
Definition: qcompare.h:77
static const QPartialOrdering Equivalent
Definition: qcompare.h:76
static const QPartialOrdering Unordered
Definition: qcompare.h:78
The QPersistentModelIndex class is used to locate data in a data model.
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:242
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:52
The QRectF class defines a finite rectangle in the plane using floating point precision.
Definition: qrect.h:511
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QRegularExpression class provides pattern matching using regular expressions.
The QSizeF class defines the size of a two-dimensional object using floating point precision.
Definition: qsize.h:235
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QStringList class provides a list of strings.
The QTime class provides clock time functions.
Definition: qdatetime.h:166
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:130
The QUuid class stores a Universally Unique Identifier (UUID).
Definition: quuid.h:67
QVariantConstPointer(QVariant variant)
Definition: qvariant.cpp:2862
const QVariant * operator->() const
Definition: qvariant.cpp:2879
QVariant operator*() const
Definition: qvariant.cpp:2870
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:95
QChar toChar() const
Definition: qvariant.cpp:1783
void * data()
Definition: qvariant.cpp:2464
bool convert(QMetaType type)
Definition: qvariant.cpp:2049
QVariant() noexcept
Definition: qvariant.h:173
void clear()
Definition: qvariant.cpp:1082
QPointF toPointF() const
Definition: qvariant.cpp:1627
T view()
Definition: qvariant.h:382
static QPartialOrdering compare(const QVariant &lhs, const QVariant &rhs)
Definition: qvariant.cpp:2429
qreal toReal(bool *ok=nullptr) const
Definition: qvariant.cpp:1967
QDateTime toDateTime() const
Definition: qvariant.cpp:1489
bool isValid() const
Definition: qvariant.h:582
QJsonValue toJsonValue() const
Definition: qvariant.cpp:1729
double toDouble(bool *ok=nullptr) const
Definition: qvariant.cpp:1929
QList< QVariant > toList() const
Definition: qvariant.cpp:1979
QMap< QString, QVariant > toMap() const
Definition: qvariant.cpp:1427
qlonglong toLongLong(bool *ok=nullptr) const
Definition: qvariant.cpp:1872
QPoint toPoint() const
Definition: qvariant.cpp:1534
int toInt(bool *ok=nullptr) const
Definition: qvariant.cpp:1833
QLocale toLocale() const
Definition: qvariant.cpp:1657
QSize toSize() const
Definition: qvariant.cpp:1560
void save(QDataStream &ds) const
Definition: qvariant.cpp:1256
QTime toTime() const
Definition: qvariant.cpp:1472
float toFloat(bool *ok=nullptr) const
Definition: qvariant.cpp:1948
uint toUInt(bool *ok=nullptr) const
Definition: qvariant.cpp:1855
QString toString() const
Definition: qvariant.cpp:1416
void load(QDataStream &ds)
Definition: qvariant.cpp:1176
bool toBool() const
Definition: qvariant.cpp:1906
QBitArray toBitArray() const
Definition: qvariant.cpp:1794
QJsonArray toJsonArray() const
Definition: qvariant.cpp:1755
QHash< QString, QVariant > toHash() const
Definition: qvariant.cpp:1438
int typeId() const
Definition: qvariant.h:241
bool isNull() const
Definition: qvariant.cpp:2483
const char * typeName() const
Definition: qvariant.cpp:1073
QJsonDocument toJsonDocument() const
Definition: qvariant.cpp:1768
QRectF toRectF() const
Definition: qvariant.cpp:1587
QLineF toLineF() const
Definition: qvariant.cpp:1600
void detach()
Definition: qvariant.cpp:1049
QVariant & operator=(const QVariant &other)
Definition: qvariant.cpp:1011
QJsonObject toJsonObject() const
Definition: qvariant.cpp:1742
bool canConvert(QMetaType targetType) const
Definition: qvariant.h:246
QRect toRect() const
Definition: qvariant.cpp:1547
QSizeF toSizeF() const
Definition: qvariant.cpp:1573
QUuid toUuid() const
Definition: qvariant.cpp:1715
QDate toDate() const
Definition: qvariant.cpp:1455
QByteArray toByteArray() const
Definition: qvariant.cpp:1519
QLine toLine() const
Definition: qvariant.cpp:1613
Private d
Definition: qvariant.h:533
void create(int type, const void *copy)
Definition: qvariant.cpp:484
QMetaType metaType() const
Definition: qvariant.cpp:1003
qulonglong toULongLong(bool *ok=nullptr) const
Definition: qvariant.cpp:1889
const void * constData() const
Definition: qvariant.h:350
QStringList toStringList() const
Definition: qvariant.cpp:1396
QUrl toUrl() const
Definition: qvariant.cpp:1643
bool equals(const QVariant &other) const
Definition: qvariant.cpp:2372
const void * coerce(const QVariant &value, const QMetaType &type)
Definition: qvariant.cpp:2784
const void * convert(const QVariant &value, const QMetaType &type)
Definition: qvariant.cpp:2764
QHash< int, QWidget * > hash
[35multi]
QMap< QString, QString > map
[6]
QStyleOptionButton opt
unsigned short UShort
Definition: ftraster.c:310
long Long
Definition: ftraster.c:311
char Bool
Definition: ftraster.c:315
unsigned long ULong
Definition: ftraster.c:312
int Int
Definition: ftraster.c:307
unsigned int UInt
Definition: ftraster.c:308
short Short
Definition: ftraster.c:309
const char * typedefNameForType(const QtPrivate::QMetaTypeInterface *type_d)
Definition: qmetatype.cpp:187
Q_CORE_EXPORT Q_DECL_PURE_FUNCTION ParsedNumber< double > toDouble(QByteArrayView a) noexcept
Definition: qfloat16.h:381
#define QString()
Definition: parse-defines.h:51
int PRIV() strcmp(PCRE2_SPTR str1, PCRE2_SPTR str2)
QCborSimpleType
Definition: qcborcommon.h:59
#define Q_FALLTHROUGH()
#define QT_WARNING_POP
#define QT_WARNING_DISABLE_DEPRECATED
#define Q_UNREACHABLE()
#define QT_WARNING_PUSH
QMap< QString, QVariant > QVariantMap
Definition: qcontainerfwd.h:75
QList< QString > QStringList
Definition: qcontainerfwd.h:64
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
EGLOutputLayerEXT EGLint EGLAttrib value
qint64 qRound64(qfloat16 d) noexcept
Definition: qfloat16.h:230
#define Q_UINT64_C(c)
Definition: qglobal.h:296
unsigned int quint32
Definition: qglobal.h:288
unsigned long ulong
Definition: qglobal.h:335
QT_END_INCLUDE_NAMESPACE typedef double qreal
Definition: qglobal.h:341
quint64 qulonglong
Definition: qglobal.h:302
unsigned int uint
Definition: qglobal.h:334
unsigned short ushort
Definition: qglobal.h:333
QT_BEGIN_NAMESPACE typedef signed char qint8
Definition: qglobal.h:283
qint64 qlonglong
Definition: qglobal.h:301
#define Q_INT64_C(c)
Definition: qglobal.h:295
QList< QVariant > QVariantList
Definition: qjsonarray.h:50
#define qWarning
Definition: qlogging.h:179
GLenum type
Definition: qopengl.h:270
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLboolean r
[2]
GLfloat GLfloat f
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
[4]
GLbitfield flags
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint name
GLuint res
Definition: qopenglext.h:8867
GLuint GLfloat * val
Definition: qopenglext.h:1513
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
GLdouble s
[6]
Definition: qopenglext.h:235
GLfloat GLfloat p
[1]
Definition: qopenglext.h:12698
#define Q_ASSERT(cond)
Definition: qrandom.cpp:84
#define Q_ASSERT_X(cond, x, msg)
Definition: qrandom.cpp:85
QT_BEGIN_NAMESPACE typedef char Char
constexpr int Qt6ToQt5GuiTypeDelta
Definition: qvariant.cpp:1168
constexpr int Qt5QQuaternion
Definition: qvariant.cpp:1166
constexpr int Qt5KeySequence
Definition: qvariant.cpp:1165
constexpr int Qt5LastCoreType
Definition: qvariant.cpp:1160
constexpr int Qt5FirstGuiType
Definition: qvariant.cpp:1161
@ MapFromThreeCount
Definition: qvariant.cpp:1111
constexpr int Qt5RegExp
Definition: qvariant.cpp:1164
constexpr int Qt5LastGuiType
Definition: qvariant.cpp:1162
constexpr int Qt5SizePolicy
Definition: qvariant.cpp:1163
constexpr int Qt5UserType
Definition: qvariant.cpp:1159
T qNumVariantToHelper(const QVariant::Private &d, bool *ok, const T &val)
Definition: qvariant.cpp:1800
QVariant variant
[1]
v canConvert< QString >()
QCborValue(QCborTag(2), QByteArray("\x01\0\0\0\0\0\0\0\0", 9))
[0]
QDate d1(1995, 5, 17)
[0]
QDate d2(1995, 5, 20)
QBitArray().isNull()
[3]
Definition: qbitarray.h:149
QRect r1(100, 200, 11, 16)
[0]
QRect r2(QPoint(100, 200), QSize(11, 16))
QSharedPointer< T > other(t)
[5]
QSize t2(10, 12)
QDBusVariant Type
QStringList list
[0]
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:165
const void * storage() const
Definition: qvariant.h:486
int typeId() const
Definition: qvariant.h:510
QtPrivate::QMetaTypeInterface * typeInterface() const
Definition: qvariant.h:505
quintptr is_shared
Definition: qvariant.h:473
static constexpr bool canUseInternalSpace(QtPrivate::QMetaTypeInterface *type)
Definition: qvariant.h:460
quintptr is_null
Definition: qvariant.h:474
uchar data[MaxInternalSize]
Definition: qvariant.h:469
const T & get() const
Definition: qvariant.h:494
void set(const T &t)
Definition: qvariant.h:497
QMetaType type() const
Definition: qvariant.h:500
static PrivateShared * create(const QtPrivate::QMetaTypeInterface *type)
Definition: qvariant.h:422
static void free(PrivateShared *p)
Definition: qvariant.h:441
Definition: main.cpp:38
#define smaller(tree, n, m, depth)
Definition: trees.c:441
U convert(const T &t)
#define rhs