-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
Copy pathqvariant.cpp
3031 lines (2452 loc) · 90.8 KB
/
qvariant.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
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
437
438
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
469
470
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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
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
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
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
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (C) 2022 The Qt Company Ltd.
// Copyright (C) 2021 Intel Corporation.
// Copyright (C) 2015 Olivier Goffart <ogoffart@woboq.com>
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qvariant_p.h"
#include "qbitarray.h"
#include "qbytearray.h"
#include "qdatastream.h"
#include "qdebug.h"
#include "qmap.h"
#include "qhash.h"
#include "qdatetime.h"
#if QT_CONFIG(easingcurve)
#include "qeasingcurve.h"
#endif
#include "qlist.h"
#if QT_CONFIG(regularexpression)
#include "qregularexpression.h"
#endif
#include "qstring.h"
#include "qstringlist.h"
#include "qurl.h"
#include "qlocale.h"
#include "quuid.h"
#if QT_CONFIG(itemmodel)
#include "qabstractitemmodel.h"
#endif
#ifndef QT_BOOTSTRAPPED
#include "qcborarray.h"
#include "qcborcommon.h"
#include "qcbormap.h"
#include "qjsonvalue.h"
#include "qjsonobject.h"
#include "qjsonarray.h"
#include "qjsondocument.h"
#include "qbytearraylist.h"
#endif
#include "private/qlocale_p.h"
#include "qmetatype_p.h"
#include <qmetaobject.h>
#ifndef QT_NO_GEOM_VARIANT
#include "qsize.h"
#include "qpoint.h"
#include "qrect.h"
#include "qline.h"
#endif
#include <memory>
#include <cmath>
#include <float.h>
#include <cstring>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace { // anonymous used to hide QVariant handlers
static qlonglong qMetaTypeNumberBySize(const QVariant::Private *d)
{
switch (d->typeInterface()->size) {
case 1:
return d->get<signed char>();
case 2:
return d->get<short>();
case 4:
return d->get<int>();
case 8:
return d->get<qlonglong>();
}
Q_UNREACHABLE_RETURN(0);
}
static qlonglong qMetaTypeNumber(const QVariant::Private *d)
{
switch (d->typeInterface()->typeId) {
case QMetaType::Int:
case QMetaType::LongLong:
case QMetaType::Char:
case QMetaType::SChar:
case QMetaType::Short:
case QMetaType::Long:
return qMetaTypeNumberBySize(d);
case QMetaType::Float:
return qRound64(d->get<float>());
case QMetaType::Double:
return qRound64(d->get<double>());
#ifndef QT_BOOTSTRAPPED
case QMetaType::QJsonValue:
return d->get<QJsonValue>().toDouble();
case QMetaType::QCborValue:
return d->get<QCborValue>().toInteger();
#endif
}
Q_UNREACHABLE_RETURN(0);
}
static qulonglong qMetaTypeUNumber(const QVariant::Private *d)
{
switch (d->typeInterface()->size) {
case 1:
return d->get<unsigned char>();
case 2:
return d->get<unsigned short>();
case 4:
return d->get<unsigned int>();
case 8:
return d->get<qulonglong>();
}
Q_UNREACHABLE_RETURN(0);
}
static std::optional<qlonglong> qConvertToNumber(const QVariant::Private *d, bool allowStringToBool = false)
{
bool ok;
switch (d->typeInterface()->typeId) {
case QMetaType::QString: {
const QString &s = d->get<QString>();
if (qlonglong l = s.toLongLong(&ok); ok)
return l;
if (allowStringToBool) {
if (s == "false"_L1 || s == "0"_L1)
return 0;
if (s == "true"_L1 || s == "1"_L1)
return 1;
}
return std::nullopt;
}
case QMetaType::QChar:
return d->get<QChar>().unicode();
case QMetaType::QByteArray:
if (qlonglong l = d->get<QByteArray>().toLongLong(&ok); ok)
return l;
return std::nullopt;
case QMetaType::Bool:
return qlonglong(d->get<bool>());
#ifndef QT_BOOTSTRAPPED
case QMetaType::QCborValue:
if (!d->get<QCborValue>().isInteger() && !d->get<QCborValue>().isDouble())
break;
return qMetaTypeNumber(d);
case QMetaType::QJsonValue:
if (!d->get<QJsonValue>().isDouble())
break;
Q_FALLTHROUGH();
#endif
case QMetaType::Double:
case QMetaType::Int:
case QMetaType::Char:
case QMetaType::SChar:
case QMetaType::Short:
case QMetaType::Long:
case QMetaType::Float:
case QMetaType::LongLong:
return qMetaTypeNumber(d);
case QMetaType::ULongLong:
case QMetaType::UInt:
case QMetaType::UChar:
case QMetaType::Char16:
case QMetaType::Char32:
case QMetaType::UShort:
case QMetaType::ULong:
return qlonglong(qMetaTypeUNumber(d));
}
if (d->typeInterface()->flags & QMetaType::IsEnumeration
|| d->typeInterface()->typeId == QMetaType::QCborSimpleType)
return qMetaTypeNumberBySize(d);
return std::nullopt;
}
static std::optional<double> qConvertToRealNumber(const QVariant::Private *d)
{
bool ok;
switch (d->typeInterface()->typeId) {
case QMetaType::QString:
if (double r = d->get<QString>().toDouble(&ok); ok)
return r;
return std::nullopt;
case QMetaType::Double:
return d->get<double>();
case QMetaType::Float:
return double(d->get<float>());
case QMetaType::Float16:
return double(d->get<qfloat16>());
case QMetaType::ULongLong:
case QMetaType::UInt:
case QMetaType::UChar:
case QMetaType::Char16:
case QMetaType::Char32:
case QMetaType::UShort:
case QMetaType::ULong:
return double(qMetaTypeUNumber(d));
#ifndef QT_BOOTSTRAPPED
case QMetaType::QCborValue:
return d->get<QCborValue>().toDouble();
case QMetaType::QJsonValue:
return d->get<QJsonValue>().toDouble();
#endif
default:
// includes enum conversion as well as invalid types
if (std::optional<qlonglong> l = qConvertToNumber(d))
return double(*l);
return std::nullopt;
}
}
static bool isValidMetaTypeForVariant(const QtPrivate::QMetaTypeInterface *iface, const void *copy)
{
using namespace QtMetaTypePrivate;
if (!iface || iface->size == 0)
return false;
Q_ASSERT(!isInterfaceFor<void>(iface)); // only void should have size 0
if (!isCopyConstructible(iface) || !isDestructible(iface)) {
// all meta types must be copyable (because QVariant is) and
// destructible (because QVariant owns it)
qWarning("QVariant: Provided metatype for '%s' does not support destruction and "
"copy construction", iface->name);
return false;
}
if (!copy && !isDefaultConstructible(iface)) {
// non-default-constructible types are acceptable, but not if you're
// asking us to construct from nothing
qWarning("QVariant: Cannot create type '%s' without a default constructor", iface->name);
return false;
}
return true;
}
enum CustomConstructMoveOptions {
UseCopy, // custom construct uses the copy ctor unconditionally
// future option: TryMove: uses move ctor if available, else copy ctor
ForceMove, // custom construct use the move ctor (which must exist)
};
enum CustomConstructNullabilityOption {
MaybeNull, // copy might be null, might be non-null
NonNull, // copy is guarantueed to be non-null
// future option: AlwaysNull?
};
// the type of d has already been set, but other field are not set
template <CustomConstructMoveOptions moveOption = UseCopy, CustomConstructNullabilityOption nullability = MaybeNull>
static void customConstruct(const QtPrivate::QMetaTypeInterface *iface, QVariant::Private *d,
std::conditional_t<moveOption == ForceMove, void *, const void *> copy)
{
using namespace QtMetaTypePrivate;
Q_ASSERT(iface);
Q_ASSERT(iface->size);
Q_ASSERT(!isInterfaceFor<void>(iface));
Q_ASSERT(isCopyConstructible(iface));
Q_ASSERT(isDestructible(iface));
Q_ASSERT(copy || isDefaultConstructible(iface));
if constexpr (moveOption == ForceMove)
Q_ASSERT(isMoveConstructible(iface));
if constexpr (nullability == NonNull)
Q_ASSERT(copy != nullptr);
// need to check for nullptr_t here, as this can get called by fromValue(nullptr). fromValue() uses
// std::addressof(value) which in this case returns the address of the nullptr object.
// ### Qt 7: remove nullptr_t special casing
d->is_null = !copy QT6_ONLY(|| isInterfaceFor<std::nullptr_t>(iface));
if (QVariant::Private::canUseInternalSpace(iface)) {
d->is_shared = false;
if (!copy && !iface->defaultCtr)
return; // trivial default constructor and it's OK to build in 0-filled storage, which we've already done
if constexpr (moveOption == ForceMove && nullability == NonNull)
moveConstruct(iface, d->data.data, copy);
else
construct(iface, d->data.data, copy);
} else {
d->data.shared = customConstructShared(iface->size, iface->alignment, [=](void *where) {
if constexpr (moveOption == ForceMove && nullability == NonNull)
moveConstruct(iface, where, copy);
else
construct(iface, where, copy);
});
d->is_shared = true;
}
}
static void customClear(QVariant::Private *d)
{
const QtPrivate::QMetaTypeInterface *iface = d->typeInterface();
if (!iface)
return;
if (!d->is_shared) {
QtMetaTypePrivate::destruct(iface, d->data.data);
} else {
QtMetaTypePrivate::destruct(iface, d->data.shared->data());
QVariant::PrivateShared::free(d->data.shared);
}
}
static QVariant::Private clonePrivate(const QVariant::Private &other)
{
QVariant::Private d = other;
if (d.is_shared) {
d.data.shared->ref.ref();
} else if (const QtPrivate::QMetaTypeInterface *iface = d.typeInterface()) {
Q_ASSERT(d.canUseInternalSpace(iface));
// if not trivially copyable, ask to copy
if (iface->copyCtr)
QtMetaTypePrivate::copyConstruct(iface, d.data.data, other.data.data);
}
return d;
}
} // anonymous used to hide QVariant handlers
/*!
\class QVariant
\inmodule QtCore
\brief The QVariant class acts like a union for the most common Qt data types.
\ingroup objectmodel
\ingroup shared
\compares equality
Because C++ forbids unions from including types that have
non-default constructors or destructors, most interesting Qt
classes cannot be used in unions. Without QVariant, this would be
a problem for QObject::property() and for database work, etc.
A QVariant object holds a single value of a single typeId() at a
time. (Some types are multi-valued, for example a string list.)
You can find out what type, T, the variant holds, convert it to a
different type using convert(), get its value using one of the
toT() functions (e.g., toSize()), and check whether the type can
be converted to a particular type using canConvert().
The methods named toT() (e.g., toInt(), toString()) are const. If
you ask for the stored type, they return a copy of the stored
object. If you ask for a type that can be generated from the
stored type, toT() copies and converts and leaves the object
itself unchanged. If you ask for a type that cannot be generated
from the stored type, the result depends on the type; see the
function documentation for details.
Here is some example code to demonstrate the use of QVariant:
\snippet code/src_corelib_kernel_qvariant.cpp 0
You can even store QList<QVariant> and QMap<QString, QVariant>
values in a variant, so you can easily construct arbitrarily
complex data structures of arbitrary types. This is very powerful
and versatile, but may prove less memory and speed efficient than
storing specific types in standard data structures.
QVariant also supports the notion of null values. A variant is null
if the variant contains no initialized value, or contains a null pointer.
\snippet code/src_corelib_kernel_qvariant.cpp 1
QVariant can be extended to support other types than those
mentioned in the \l QMetaType::Type enum.
See \l{Creating Custom Qt Types}{Creating Custom Qt Types} for details.
\section1 A Note on GUI Types
Because QVariant is part of the Qt Core module, it cannot provide
conversion functions to data types defined in Qt GUI, such as
QColor, QImage, and QPixmap. In other words, there is no \c
toColor() function. Instead, you can use the QVariant::value() or
the qvariant_cast() template function. For example:
\snippet code/src_corelib_kernel_qvariant.cpp 2
The inverse conversion (e.g., from QColor to QVariant) is
automatic for all data types supported by QVariant, including
GUI-related types:
\snippet code/src_corelib_kernel_qvariant.cpp 3
\section1 Using canConvert() and convert() Consecutively
When using canConvert() and convert() consecutively, it is possible for
canConvert() to return true, but convert() to return false. This
is typically because canConvert() only reports the general ability of
QVariant to convert between types given suitable data; it is still
possible to supply data which cannot actually be converted.
For example, \c{canConvert(QMetaType::fromType<int>())} would return true
when called on a variant containing a string because, in principle,
QVariant is able to convert strings of numbers to integers.
However, if the string contains non-numeric characters, it cannot be
converted to an integer, and any attempt to convert it will fail.
Hence, it is important to have both functions return true for a
successful conversion.
\sa QMetaType
*/
/*!
\deprecated Use \l QMetaType::Type instead.
\enum QVariant::Type
This enum type defines the types of variable that a QVariant can
contain.
\value Invalid no type
\value BitArray a QBitArray
\value Bitmap a QBitmap
\value Bool a bool
\value Brush a QBrush
\value ByteArray a QByteArray
\value Char a QChar
\value Color a QColor
\value Cursor a QCursor
\value Date a QDate
\value DateTime a QDateTime
\value Double a double
\value EasingCurve a QEasingCurve
\value Uuid a QUuid
\value ModelIndex a QModelIndex
\value [since 5.5] PersistentModelIndex a QPersistentModelIndex
\value Font a QFont
\value Hash a QVariantHash
\value Icon a QIcon
\value Image a QImage
\value Int an int
\value KeySequence a QKeySequence
\value Line a QLine
\value LineF a QLineF
\value List a QVariantList
\value Locale a QLocale
\value LongLong a \l qlonglong
\value Map a QVariantMap
\value Transform a QTransform
\value Matrix4x4 a QMatrix4x4
\value Palette a QPalette
\value Pen a QPen
\value Pixmap a QPixmap
\value Point a QPoint
\value PointF a QPointF
\value Polygon a QPolygon
\value PolygonF a QPolygonF
\value Quaternion a QQuaternion
\value Rect a QRect
\value RectF a QRectF
\value RegularExpression a QRegularExpression
\value Region a QRegion
\value Size a QSize
\value SizeF a QSizeF
\value SizePolicy a QSizePolicy
\value String a QString
\value StringList a QStringList
\value TextFormat a QTextFormat
\value TextLength a QTextLength
\value Time a QTime
\value UInt a \l uint
\value ULongLong a \l qulonglong
\value Url a QUrl
\value Vector2D a QVector2D
\value Vector3D a QVector3D
\value Vector4D a QVector4D
\value UserType Base value for user-defined types.
\omitvalue LastGuiType
\omitvalue LastCoreType
\omitvalue LastType
*/
/*!
\fn QVariant::QVariant(QVariant &&other)
Move-constructs a QVariant instance, making it point at the same
object that \a other was pointing to.
\since 5.2
*/
/*!
\fn QVariant &QVariant::operator=(QVariant &&other)
Move-assigns \a other to this QVariant instance.
\since 5.2
*/
/*!
\fn QVariant::QVariant()
Constructs an invalid variant.
*/
/*!
\fn QVariant::create(int type, const void *copy)
\internal
Constructs a variant private of type \a type, and initializes with \a copy if
\a copy is not \nullptr.
*/
//### Qt 7: Remove in favor of QMetaType overload
void QVariant::create(int type, const void *copy)
{
create(QMetaType(type), copy);
}
/*!
\fn QVariant::create(int type, const void *copy)
\internal
\overload
*/
void QVariant::create(QMetaType type, const void *copy)
{
*this = QVariant::fromMetaType(type, copy);
}
/*!
\fn QVariant::~QVariant()
Destroys the QVariant and the contained object.
*/
QVariant::~QVariant()
{
if (!d.is_shared || !d.data.shared->ref.deref())
customClear(&d);
}
/*!
\fn QVariant::QVariant(const QVariant &p)
Constructs a copy of the variant, \a p, passed as the argument to
this constructor.
*/
QVariant::QVariant(const QVariant &p)
: d(clonePrivate(p.d))
{
}
/*!
\fn template <typename T, typename... Args, QVariant::if_constructible<T, Args...> = true> QVariant::QVariant(std::in_place_type_t<T>, Args&&... args) noexcept(is_noexcept_constructible<q20::remove_cvref_t<T>, Args...>::value)
\since 6.6
Constructs a new variant containing a value of type \c T. The contained
value is is initialized with the arguments
\c{std::forward<Args>(args)...}.
This overload only participates in overload resolution if \c T can be
constructed from \a args.
This constructor is provided for STL/std::any compatibility.
\overload
*/
/*!
\fn template <typename T, typename U, typename... Args, QVariant::if_constructible<T, std::initializer_list<U> &, Args...> = true> explicit QVariant::QVariant(std::in_place_type_t<T>, std::initializer_list<U> il, Args&&... args) noexcept(is_noexcept_constructible<q20::remove_cvref_t<T>, std::initializer_list<U> &, Args... >::value)
\since 6.6
\overload
This overload exists to support types with constructors taking an
\c initializer_list. It behaves otherwise equivalent to the
non-initializer list \c{in_place_type_t} overload.
*/
/*!
\fn template <typename T, typename... Args, QVariant::if_constructible<T, Args...> = true> QVariant::emplace(Args&&... args)
\since 6.6
Replaces the object currently held in \c{*this} with an object of
type \c{T}, constructed from \a{args}\c{...}. If \c{*this} was non-null,
the previously held object is destroyed first.
If possible, this method will reuse memory allocated by the QVariant.
Returns a reference to the newly-created object.
*/
/*!
\fn template <typename T, typename U, typename... Args, QVariant::if_constructible<T, std::initializer_list<U> &, Args...> = true> QVariant::emplace(std::initializer_list<U> list, Args&&... args)
\since 6.6
\overload
This overload exists to support types with constructors taking an
\c initializer_list. It behaves otherwise equivalent to the
non-initializer list overload.
*/
QVariant::QVariant(std::in_place_t, QMetaType type) : d(type.iface())
{
// we query the metatype instead of detecting it at compile time
// so that we can change relocatability of internal types
if (!Private::canUseInternalSpace(type.iface())) {
d.data.shared = PrivateShared::create(type.sizeOf(), type.alignOf());
d.is_shared = true;
}
}
/*!
\internal
Returns a pointer to data suitable for placement new
of an object of type \a type
Changes the variant's metatype to \a type
*/
void *QVariant::prepareForEmplace(QMetaType type)
{
/* There are two cases where we can reuse the existing storage
(1) The new type fits in QVariant's SBO storage
(2) We are using the externally allocated storage, the variant is
detached, and the new type fits into the existing storage.
In all other cases (3), we cannot reuse the storage.
*/
auto typeFits = [&] {
auto newIface = type.iface();
auto oldIface = d.typeInterface();
auto newSize = PrivateShared::computeAllocationSize(newIface->size, newIface->alignment);
auto oldSize = PrivateShared::computeAllocationSize(oldIface->size, oldIface->alignment);
return newSize <= oldSize;
};
if (Private::canUseInternalSpace(type.iface())) { // (1)
clear();
d.packedType = quintptr(type.iface()) >> 2;
return d.data.data;
} else if (d.is_shared && isDetached() && typeFits()) { // (2)
QtMetaTypePrivate::destruct(d.typeInterface(), d.data.shared->data());
// compare QVariant::PrivateShared::create
const auto ps = d.data.shared;
const auto align = type.alignOf();
ps->offset = PrivateShared::computeOffset(ps, align);
d.packedType = quintptr(type.iface()) >> 2;
return ps->data();
}
// (3)
QVariant newVariant(std::in_place, type);
swap(newVariant);
// const cast is safe, we're in a non-const method
return const_cast<void *>(d.storage());
}
/*!
\fn QVariant::QVariant(const QString &val) noexcept
Constructs a new variant with a string value, \a val.
*/
/*!
\fn QVariant::QVariant(QLatin1StringView val)
Constructs a new variant with a QString value from the Latin-1
string viewed by \a val.
*/
/*!
\fn QVariant::QVariant(const char *val)
Constructs a new variant with a string value of \a val.
The variant creates a deep copy of \a val into a QString assuming
UTF-8 encoding on the input \a val.
Note that \a val is converted to a QString for storing in the
variant and QVariant::userType() will return QMetaType::QString for
the variant.
You can disable this operator by defining \c
QT_NO_CAST_FROM_ASCII when you compile your applications.
*/
/*!
\fn QVariant::QVariant(const QStringList &val) noexcept
Constructs a new variant with a string list value, \a val.
*/
/*!
\fn QVariant::QVariant(const QMap<QString, QVariant> &val) noexcept
Constructs a new variant with a map of \l {QVariant}s, \a val.
*/
/*!
\fn QVariant::QVariant(const QHash<QString, QVariant> &val) noexcept
Constructs a new variant with a hash of \l {QVariant}s, \a val.
*/
/*!
\fn QVariant::QVariant(QDate val) noexcept
Constructs a new variant with a date value, \a val.
*/
/*!
\fn QVariant::QVariant(QTime val) noexcept
Constructs a new variant with a time value, \a val.
*/
/*!
\fn QVariant::QVariant(const QDateTime &val) noexcept
Constructs a new variant with a date/time value, \a val.
*/
/*!
\since 4.7
\fn QVariant::QVariant(const QEasingCurve &val)
Constructs a new variant with an easing curve value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(QUuid val) noexcept
Constructs a new variant with an uuid value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(const QModelIndex &val) noexcept
Constructs a new variant with a QModelIndex value, \a val.
*/
/*!
\since 5.5
\fn QVariant::QVariant(const QPersistentModelIndex &val)
Constructs a new variant with a QPersistentModelIndex value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(const QJsonValue &val)
Constructs a new variant with a json value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(const QJsonObject &val)
Constructs a new variant with a json object value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(const QJsonArray &val)
Constructs a new variant with a json array value, \a val.
*/
/*!
\since 5.0
\fn QVariant::QVariant(const QJsonDocument &val)
Constructs a new variant with a json document value, \a val.
*/
/*!
\fn QVariant::QVariant(const QByteArray &val) noexcept
Constructs a new variant with a bytearray value, \a val.
*/
/*!
\fn QVariant::QVariant(const QBitArray &val) noexcept
Constructs a new variant with a bitarray value, \a val.
*/
/*!
\fn QVariant::QVariant(QPoint val) noexcept
Constructs a new variant with a point value of \a val.
*/
/*!
\fn QVariant::QVariant(QPointF val) noexcept
Constructs a new variant with a point value of \a val.
*/
/*!
\fn QVariant::QVariant(QRectF val)
Constructs a new variant with a rect value of \a val.
*/
/*!
\fn QVariant::QVariant(QLineF val) noexcept
Constructs a new variant with a line value of \a val.
*/
/*!
\fn QVariant::QVariant(QLine val) noexcept
Constructs a new variant with a line value of \a val.
*/
/*!
\fn QVariant::QVariant(QRect val) noexcept
Constructs a new variant with a rect value of \a val.
*/
/*!
\fn QVariant::QVariant(QSize val) noexcept
Constructs a new variant with a size value of \a val.
*/
/*!
\fn QVariant::QVariant(QSizeF val) noexcept
Constructs a new variant with a size value of \a val.
*/
/*!
\fn QVariant::QVariant(const QUrl &val) noexcept
Constructs a new variant with a url value of \a val.
*/
/*!
\fn QVariant::QVariant(int val) noexcept
Constructs a new variant with an integer value, \a val.
*/
/*!
\fn QVariant::QVariant(uint val) noexcept
Constructs a new variant with an unsigned integer value, \a val.
*/
/*!
\fn QVariant::QVariant(qlonglong val) noexcept
Constructs a new variant with a long long integer value, \a val.
*/
/*!
\fn QVariant::QVariant(qulonglong val) noexcept
Constructs a new variant with an unsigned long long integer value, \a val.
*/
/*!
\fn QVariant::QVariant(bool val) noexcept
Constructs a new variant with a boolean value, \a val.
*/
/*!
\fn QVariant::QVariant(double val) noexcept
Constructs a new variant with a floating point value, \a val.
*/
/*!
\fn QVariant::QVariant(float val) noexcept
Constructs a new variant with a floating point value, \a val.
\since 4.6
*/
/*!
\fn QVariant::QVariant(const QList<QVariant> &val) noexcept
Constructs a new variant with a list value, \a val.
*/
/*!
\fn QVariant::QVariant(QChar c) noexcept
Constructs a new variant with a char value, \a c.
*/
/*!
\fn QVariant::QVariant(const QLocale &l) noexcept
Constructs a new variant with a locale value, \a l.
*/
/*!
\fn QVariant::QVariant(const QRegularExpression &re) noexcept
\since 5.0
Constructs a new variant with the regular expression value \a re.
*/
/*! \fn QVariant::QVariant(Type type)
\deprecated [6.0] Use the constructor taking a QMetaType instead.
Constructs an uninitialized variant of type \a type. This will create a
variant in a special null state that if accessed will return a default
constructed value of the \a type.
\sa isNull()
*/
/*!
Constructs a variant of type \a type, and initializes it with
a copy of \c{*copy} if \a copy is not \nullptr (in which case, \a copy
must point to an object of type \a type).
Note that you have to pass the address of the object you want stored.
Usually, you never have to use this constructor, use QVariant::fromValue()
instead to construct variants from the pointer types represented by
\c QMetaType::VoidStar, and \c QMetaType::QObjectStar.
If \a type does not support copy construction and \a copy is not \nullptr,
the variant will be invalid. Similarly, if \a copy is \nullptr and
\a type does not support default construction, the variant will be
invalid.
\sa QVariant::fromMetaType, QVariant::fromValue(), QMetaType::Type
*/
QVariant::QVariant(QMetaType type, const void *copy)
: d()
{
*this = fromMetaType(type, copy);
}
QVariant::QVariant(int val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(uint val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(qlonglong val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(qulonglong val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(bool val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(double val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(float val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(const QByteArray &val) noexcept : d(std::piecewise_construct_t{}, val) {}
#ifndef QT_BOOTSTRAPPED
QVariant::QVariant(const QBitArray &val) noexcept : d(std::piecewise_construct_t{}, val) {}
#endif
QVariant::QVariant(const QString &val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(QChar val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(const QStringList &val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(QDate val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(QTime val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(const QDateTime &val) noexcept : d(std::piecewise_construct_t{}, val) {}
QVariant::QVariant(const QList<QVariant> &list) noexcept : d(std::piecewise_construct_t{}, list) {}
QVariant::QVariant(const QMap<QString, QVariant> &map) noexcept : d(std::piecewise_construct_t{}, map) {}
QVariant::QVariant(const QHash<QString, QVariant> &hash) noexcept : d(std::piecewise_construct_t{}, hash) {}
QVariant::QVariant(QLatin1StringView val) : QVariant(QString(val)) {}
#if QT_CONFIG(easingcurve)
QVariant::QVariant(const QEasingCurve &val) : d(std::piecewise_construct_t{}, val) {}
#endif
#ifndef QT_NO_GEOM_VARIANT
QVariant::QVariant(QPoint pt) noexcept
: d(std::piecewise_construct_t{}, pt) {}
QVariant::QVariant(QPointF pt) noexcept(Private::FitsInInternalSize<sizeof(qreal) * 2>)
: d(std::piecewise_construct_t{}, pt) {}
QVariant::QVariant(QRect r) noexcept(Private::FitsInInternalSize<sizeof(int) * 4>)
: d(std::piecewise_construct_t{}, r) {}
QVariant::QVariant(QRectF r) noexcept(Private::FitsInInternalSize<sizeof(qreal) * 4>)
: d(std::piecewise_construct_t{}, r) {}
QVariant::QVariant(QLine l) noexcept(Private::FitsInInternalSize<sizeof(int) * 4>)
: d(std::piecewise_construct_t{}, l) {}
QVariant::QVariant(QLineF l) noexcept(Private::FitsInInternalSize<sizeof(qreal) * 4>)
: d(std::piecewise_construct_t{}, l) {}
QVariant::QVariant(QSize s) noexcept
: d(std::piecewise_construct_t{}, s) {}
QVariant::QVariant(QSizeF s) noexcept(Private::FitsInInternalSize<sizeof(qreal) * 2>)
: d(std::piecewise_construct_t{}, s) {}
#endif
#ifndef QT_BOOTSTRAPPED
QVariant::QVariant(const QUrl &u) noexcept : d(std::piecewise_construct_t{}, u) {}
#endif
QVariant::QVariant(const QLocale &l) noexcept : d(std::piecewise_construct_t{}, l) {}
#if QT_CONFIG(regularexpression)
QVariant::QVariant(const QRegularExpression &re) noexcept : d(std::piecewise_construct_t{}, re) {}
#endif // QT_CONFIG(regularexpression)
QVariant::QVariant(QUuid uuid) noexcept(Private::FitsInInternalSize<16>) : d(std::piecewise_construct_t{}, uuid) {}
#ifndef QT_BOOTSTRAPPED
QVariant::QVariant(const QJsonValue &jsonValue) noexcept(Private::FitsInInternalSize<sizeof(CborValueStandIn)>)
: d(std::piecewise_construct_t{}, jsonValue)
{ static_assert(sizeof(CborValueStandIn) == sizeof(QJsonValue)); }
QVariant::QVariant(const QJsonObject &jsonObject) noexcept : d(std::piecewise_construct_t{}, jsonObject) {}
QVariant::QVariant(const QJsonArray &jsonArray) noexcept : d(std::piecewise_construct_t{}, jsonArray) {}
QVariant::QVariant(const QJsonDocument &jsonDocument) : d(std::piecewise_construct_t{}, jsonDocument) {}
#endif // QT_BOOTSTRAPPED
#if QT_CONFIG(itemmodel)