QtBase
v6.3.1
|
The QVariant class acts like a union for the most common Qt data types. More...
#include <qvariant.h>
Classes | |
struct | Private |
struct | PrivateShared |
Public Types | |
typedef Private | DataPtr |
Static Public Member Functions | |
template<typename T > | |
static auto | fromValue (const T &value) -> std::enable_if_t< std::is_copy_constructible_v< T >, QVariant > |
template<typename... Types> | |
static QVariant | fromStdVariant (const std::variant< Types... > &value) |
static QPartialOrdering | compare (const QVariant &lhs, const QVariant &rhs) |
Protected Member Functions | |
void | create (int type, const void *copy) |
void | create (QMetaType type, const void *copy) |
bool | equals (const QVariant &other) const |
bool | convert (int type, void *ptr) const |
bool | view (int type, void *ptr) |
Protected Attributes | |
Private | d |
Friends | |
bool | operator== (const QVariant &a, const QVariant &b) |
bool | operator!= (const QVariant &a, const QVariant &b) |
template<typename T > | |
auto | operator<< (const QDebug &debug, const T &variant) -> std::enable_if_t< std::is_same_v< T, QVariant >, QDebug > |
template<typename T > | |
T | qvariant_cast (const QVariant &) |
Related Functions | |
(Note that these are not member functions.) | |
template< typename T > T | qVariantValue (const QVariant &value) |
bool | qVariantCanConvert (const QVariant &value) |
QVariantList | |
QVariantMap | |
QVariantHash | |
The QVariant class acts like a union for the most common Qt data types.
\inmodule QtCore
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:
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.
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.
Definition at line 94 of file qvariant.h.
Definition at line 565 of file qvariant.h.
|
inlinenoexcept |
Constructs an invalid variant.
Definition at line 173 of file qvariant.h.
QVariant::~QVariant | ( | ) |
Destroys the QVariant and the contained object.
Note that subclasses that reimplement clear() should reimplement the destructor to call clear(). This destructor calls clear(), but because it is the destructor, QVariant::clear() is called rather than a subclass's clear().
Definition at line 512 of file qvariant.cpp.
Constructs variant of type type, and initializes with copy if copy is not \nullptr.
Note that you have to pass the address of the variable you want stored.
Usually, you never have to use this constructor, use QVariant::fromValue() instead to construct variants from the pointer types represented by QMetaType::VoidStar
, and QMetaType::QObjectStar
.
Definition at line 819 of file qvariant.cpp.
Constructs a copy of the variant, p, passed as the argument to this constructor.
Definition at line 525 of file qvariant.cpp.
QVariant::QVariant | ( | int | val | ) |
Constructs a new variant with an integer value, val.
Definition at line 824 of file qvariant.cpp.
QVariant::QVariant | ( | uint | val | ) |
Constructs a new variant with an unsigned integer value, val.
Definition at line 827 of file qvariant.cpp.
QVariant::QVariant | ( | qlonglong | val | ) |
Constructs a new variant with a long long integer value, val.
Definition at line 830 of file qvariant.cpp.
QVariant::QVariant | ( | qulonglong | val | ) |
Constructs a new variant with an unsigned long long integer value, val.
Definition at line 833 of file qvariant.cpp.
QVariant::QVariant | ( | bool | val | ) |
Constructs a new variant with a boolean value, val.
Definition at line 836 of file qvariant.cpp.
QVariant::QVariant | ( | double | val | ) |
Constructs a new variant with a floating point value, val.
Definition at line 839 of file qvariant.cpp.
QVariant::QVariant | ( | float | val | ) |
Constructs a new variant with a floating point value, val.
Definition at line 842 of file qvariant.cpp.
|
inline |
Constructs a new variant with a string value of val. The variant creates a deep copy of val into a QString assuming UTF-8 encoding on the input val.
Note that 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 QT_NO_CAST_FROM_ASCII
when you compile your applications.
Definition at line 186 of file qvariant.h.
QVariant::QVariant | ( | const QByteArray & | val | ) |
Constructs a new variant with a bytearray value, val.
Definition at line 846 of file qvariant.cpp.
Constructs a new variant with a bitarray value, val.
Definition at line 849 of file qvariant.cpp.
Constructs a new variant with a string value, val.
Definition at line 852 of file qvariant.cpp.
QVariant::QVariant | ( | QLatin1String | val | ) |
Constructs a new variant with a string value, val.
Definition at line 858 of file qvariant.cpp.
QVariant::QVariant | ( | const QStringList & | val | ) |
Constructs a new variant with a string list value, val.
Definition at line 861 of file qvariant.cpp.
QVariant::QVariant | ( | QChar | c | ) |
Constructs a new variant with a char value, c.
Definition at line 855 of file qvariant.cpp.
QVariant::QVariant | ( | QDate | val | ) |
Constructs a new variant with a date value, val.
Definition at line 865 of file qvariant.cpp.
QVariant::QVariant | ( | QTime | val | ) |
Constructs a new variant with a time value, val.
Definition at line 868 of file qvariant.cpp.
Constructs a new variant with a date/time value, val.
Definition at line 871 of file qvariant.cpp.
Constructs a new variant with a list value, val.
Definition at line 879 of file qvariant.cpp.
Constructs a new variant with a map of \l {QVariant}s, val.
Definition at line 882 of file qvariant.cpp.
Constructs a new variant with a hash of \l {QVariant}s, val.
Definition at line 885 of file qvariant.cpp.
Constructs a new variant with a size value of val.
Definition at line 907 of file qvariant.cpp.
Constructs a new variant with a size value of val.
Definition at line 910 of file qvariant.cpp.
Constructs a new variant with a point value of val.
Definition at line 889 of file qvariant.cpp.
Constructs a new variant with a point value of val.
Definition at line 892 of file qvariant.cpp.
Constructs a new variant with a line value of val.
Definition at line 901 of file qvariant.cpp.
Constructs a new variant with a line value of val.
Definition at line 898 of file qvariant.cpp.
Constructs a new variant with a rect value of val.
Definition at line 904 of file qvariant.cpp.
Constructs a new variant with a rect value of val.
Definition at line 895 of file qvariant.cpp.
Constructs a new variant with a locale value, l.
Definition at line 919 of file qvariant.cpp.
Constructs a new variant with an uuid value, val.
Definition at line 927 of file qvariant.cpp.
Constructs a new variant with a url value of val.
Definition at line 915 of file qvariant.cpp.
QVariant::QVariant | ( | const QJsonValue & | val | ) |
Constructs a new variant with a json value, val.
Definition at line 931 of file qvariant.cpp.
QVariant::QVariant | ( | const QJsonObject & | val | ) |
Constructs a new variant with a json object value, val.
Definition at line 934 of file qvariant.cpp.
QVariant::QVariant | ( | const QJsonArray & | val | ) |
Constructs a new variant with a json array value, val.
Definition at line 937 of file qvariant.cpp.
QVariant::QVariant | ( | const QJsonDocument & | val | ) |
Constructs a new variant with a json document value, val.
Definition at line 940 of file qvariant.cpp.
|
inlinenoexcept |
Move-constructs a QVariant instance, making it point at the same object that other was pointing to.
Definition at line 234 of file qvariant.h.
|
inline |
Returns true
if the variant can be converted to the template type {T}, otherwise false.
Example:
A QVariant containing a pointer to a type derived from QObject will also return true for this function if a qobject_cast to the template type {T} would succeed. Note that this only works for QObject subclasses which use the Q_OBJECT macro.
Definition at line 409 of file qvariant.h.
|
inline |
Returns true
if the variant's type can be cast to the requested type, type. Such casting is done automatically when calling the toInt(), toBool(), ... methods.
Definition at line 246 of file qvariant.h.
|
inline |
Returns true
if a mutable view of the template type {T} can be created on this variant, otherwise
false
.
Definition at line 413 of file qvariant.h.
|
inline |
void QVariant::clear | ( | ) |
Convert this variant to type QMetaType::UnknownType and free up any resources used.
Definition at line 1082 of file qvariant.cpp.
|
static |
Compares the objects at lhs and rhs for ordering.
Returns QPartialOrdering::Unordered if comparison is not supported or the values are unordered. Otherwise, returns QPartialOrdering::Less, QPartialOrdering::Equivalent or QPartialOrdering::Greater if lhs is less than, equivalent to or greater than rhs, respectively.
If the variants contain data with a different metatype, the values are considered unordered unless they are both of numeric or pointer types, where regular numeric or pointer comparison rules will be used.
If both variants contain data of the same metatype, the method will use the QMetaType::compare method to determine the ordering of the two variants, which can also indicate that it can't establish an ordering between the two values.
Definition at line 2429 of file qvariant.cpp.
|
protected |
Definition at line 2075 of file qvariant.cpp.
bool QVariant::convert | ( | QMetaType | targetType | ) |
Casts the variant to the requested type, targetType. If the cast cannot be done, the variant is still changed to the requested type, but is left in a cleared null state similar to that constructed by QVariant(Type).
Returns true
if the current type of the variant was successfully cast; otherwise returns false
.
A QVariant containing a pointer to a type derived from QObject will also convert and return true for this function if a qobject_cast to the type described by targetType would succeed. Note that this only works for QObject subclasses which use the Q_OBJECT macro.
false
.Definition at line 2049 of file qvariant.cpp.
Definition at line 495 of file qvariant.cpp.
void * QVariant::data | ( | ) |
Returns a pointer to the contained object as a generic void* that can be written to.
This function detaches the QVariant. When called on a \l{isNull}{null-QVariant}, the QVariant will not be null after the call.
Definition at line 2464 of file qvariant.cpp.
Returns a pointer to the contained object as a generic void* that cannot be written to.
Definition at line 352 of file qvariant.h.
|
inline |
Definition at line 566 of file qvariant.h.
Definition at line 567 of file qvariant.h.
void QVariant::detach | ( | ) |
Definition at line 1049 of file qvariant.cpp.
|
inlinestatic |
Returns a QVariant with the type and value of the active variant of value. If the active type is std::monostate a default QVariant is returned.
Definition at line 401 of file qvariant.h.
|
inlinestatic |
Returns a QVariant containing a copy of value. Behaves exactly like setValue() otherwise.
Example:
Definition at line 391 of file qvariant.h.
|
inline |
Definition at line 613 of file qvariant.h.
bool QVariant::isNull | ( | ) | const |
Returns true
if this is a null variant, false otherwise.
A variant is considered null if it contains no initialized value or a null pointer.
Definition at line 2483 of file qvariant.cpp.
|
inline |
Returns true
if the storage type of this variant is not QMetaType::UnknownType; otherwise returns false
.
Definition at line 582 of file qvariant.h.
void QVariant::load | ( | QDataStream & | s | ) |
Internal function for loading a variant from stream s. Use the stream operators instead.
Definition at line 1176 of file qvariant.cpp.
QMetaType QVariant::metaType | ( | ) | const |
Returns the QMetaType of the value stored in the variant.
Definition at line 1003 of file qvariant.cpp.
Move-assigns other to this QVariant instance.
Assigns the value of the variant variant to this variant.
Definition at line 1011 of file qvariant.cpp.
void QVariant::save | ( | QDataStream & | s | ) | const |
Internal function for saving a variant to the stream s. Use the stream operators instead.
Definition at line 1256 of file qvariant.cpp.
Copies value over this QVariant. It is equivalent to simply assigning value to this QVariant.
Definition at line 367 of file qvariant.h.
Moves value over this QVariant. It is equivalent to simply move assigning value to this QVariant.
Definition at line 372 of file qvariant.h.
|
inline |
Stores a copy of value. If {T} is a type that QVariant doesn't support, QMetaType is used to store the value. A compile error will occur if QMetaType doesn't handle the type.
Example:
Definition at line 355 of file qvariant.h.
Swaps variant other with this variant. This operation is very fast and never fails.
Definition at line 238 of file qvariant.h.
QBitArray QVariant::toBitArray | ( | ) | const |
Returns the variant as a QBitArray if the variant has userType() \l QMetaType::QBitArray; otherwise returns an empty bit array.
Definition at line 1794 of file qvariant.cpp.
bool QVariant::toBool | ( | ) | const |
Returns the variant as a bool if the variant has userType() Bool.
Returns true
if the variant has userType() \l QMetaType::Bool, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::UInt, or \l QMetaType::ULongLong and the value is non-zero, or if the variant has type \l QMetaType::QString or \l QMetaType::QByteArray and its lower-case content is not one of the following: empty, "0" or "false"; otherwise returns false
.
Definition at line 1906 of file qvariant.cpp.
QByteArray QVariant::toByteArray | ( | ) | const |
Returns the variant as a QByteArray if the variant has userType() \l QMetaType::QByteArray or \l QMetaType::QString (converted using QString::fromUtf8()); otherwise returns an empty byte array.
Definition at line 1519 of file qvariant.cpp.
QChar QVariant::toChar | ( | ) | const |
Returns the variant as a QChar if the variant has userType() \l QMetaType::QChar, \l QMetaType::Int, or \l QMetaType::UInt; otherwise returns an invalid QChar.
Definition at line 1783 of file qvariant.cpp.
QDate QVariant::toDate | ( | ) | const |
Returns the variant as a QDate if the variant has userType() \l QMetaType::QDate, \l QMetaType::QDateTime, or \l QMetaType::QString; otherwise returns an invalid date.
If the type() is \l QMetaType::QString, an invalid date will be returned if the string cannot be parsed as a Qt::ISODate format date.
Definition at line 1455 of file qvariant.cpp.
QDateTime QVariant::toDateTime | ( | ) | const |
Returns the variant as a QDateTime if the variant has userType() \l QMetaType::QDateTime, \l QMetaType::QDate, or \l QMetaType::QString; otherwise returns an invalid date/time.
If the type() is \l QMetaType::QString, an invalid date/time will be returned if the string cannot be parsed as a Qt::ISODate format date/time.
Definition at line 1489 of file qvariant.cpp.
double QVariant::toDouble | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a double if the variant has userType() \l QMetaType::Double, \l QMetaType::Float, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, or \l QMetaType::ULongLong; otherwise returns 0.0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to a double; otherwise
{*}{ok} is set to false.
Definition at line 1929 of file qvariant.cpp.
float QVariant::toFloat | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a float if the variant has userType() \l QMetaType::Double, \l QMetaType::Float, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, or \l QMetaType::ULongLong; otherwise returns 0.0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to a double; otherwise
{*}{ok} is set to false.
Definition at line 1948 of file qvariant.cpp.
QVariantHash QVariant::toHash | ( | ) | const |
Returns the variant as a QHash<QString, QVariant> if the variant has type() \l QMetaType::QVariantHash; otherwise returns an empty map.
Definition at line 1438 of file qvariant.cpp.
int QVariant::toInt | ( | bool * | ok = nullptr | ) | const |
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, or \l QMetaType::ULongLong; otherwise returns 0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to an int; otherwise
{*}{ok} is set to false.
{Warning:} If the value is convertible to a \l QMetaType::LongLong but is too large to be represented in an int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toInt().
Definition at line 1833 of file qvariant.cpp.
QJsonArray QVariant::toJsonArray | ( | ) | const |
Returns the variant as a QJsonArray if the variant has userType() \l QJsonArray; otherwise returns a default constructed QJsonArray.
Definition at line 1755 of file qvariant.cpp.
QJsonDocument QVariant::toJsonDocument | ( | ) | const |
Returns the variant as a QJsonDocument if the variant has userType() \l QJsonDocument; otherwise returns a default constructed QJsonDocument.
Definition at line 1768 of file qvariant.cpp.
QJsonObject QVariant::toJsonObject | ( | ) | const |
Returns the variant as a QJsonObject if the variant has userType() \l QJsonObject; otherwise returns a default constructed QJsonObject.
Definition at line 1742 of file qvariant.cpp.
QJsonValue QVariant::toJsonValue | ( | ) | const |
Returns the variant as a QJsonValue if the variant has userType() \l QJsonValue; otherwise returns a default constructed QJsonValue.
Definition at line 1729 of file qvariant.cpp.
QLine QVariant::toLine | ( | ) | const |
Returns the variant as a QLine if the variant has userType() \l QMetaType::QLine; otherwise returns an invalid QLine.
Definition at line 1613 of file qvariant.cpp.
QLineF QVariant::toLineF | ( | ) | const |
Returns the variant as a QLineF if the variant has userType() \l QMetaType::QLineF; otherwise returns an invalid QLineF.
Definition at line 1600 of file qvariant.cpp.
QVariantList QVariant::toList | ( | ) | const |
Returns the variant as a QVariantList if the variant has userType() \l QMetaType::QVariantList or \l QMetaType::QStringList; otherwise returns an empty list.
Definition at line 1979 of file qvariant.cpp.
QLocale QVariant::toLocale | ( | ) | const |
Returns the variant as a QLocale if the variant has userType() \l QMetaType::QLocale; otherwise returns an invalid QLocale.
Definition at line 1657 of file qvariant.cpp.
Returns the variant as a long long int if the variant has userType() \l QMetaType::LongLong, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::QString, \l QMetaType::UInt, or \l QMetaType::ULongLong; otherwise returns 0.
If ok is non-null: {*}
{ok} is set to true if the value could be converted to an int; otherwise
{*}
{ok} is set to false.
Definition at line 1872 of file qvariant.cpp.
QVariantMap QVariant::toMap | ( | ) | const |
Returns the variant as a QMap<QString, QVariant> if the variant has type() \l QMetaType::QVariantMap; otherwise returns an empty map.
Definition at line 1427 of file qvariant.cpp.
QPoint QVariant::toPoint | ( | ) | const |
Returns the variant as a QPoint if the variant has userType() \l QMetaType::QPoint or \l QMetaType::QPointF; otherwise returns a null QPoint.
Definition at line 1534 of file qvariant.cpp.
QPointF QVariant::toPointF | ( | ) | const |
Returns the variant as a QPointF if the variant has userType() \l QMetaType::QPoint or \l QMetaType::QPointF; otherwise returns a null QPointF.
Definition at line 1627 of file qvariant.cpp.
Returns the variant as a qreal if the variant has userType() \l QMetaType::Double, \l QMetaType::Float, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, \l QMetaType::UInt, or \l QMetaType::ULongLong; otherwise returns 0.0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to a double; otherwise
{*}{ok} is set to false.
Definition at line 1967 of file qvariant.cpp.
QRect QVariant::toRect | ( | ) | const |
Returns the variant as a QRect if the variant has userType() \l QMetaType::QRect; otherwise returns an invalid QRect.
Definition at line 1547 of file qvariant.cpp.
QRectF QVariant::toRectF | ( | ) | const |
Returns the variant as a QRectF if the variant has userType() \l QMetaType::QRect or \l QMetaType::QRectF; otherwise returns an invalid QRectF.
Definition at line 1587 of file qvariant.cpp.
QSize QVariant::toSize | ( | ) | const |
Returns the variant as a QSize if the variant has userType() \l QMetaType::QSize; otherwise returns an invalid QSize.
Definition at line 1560 of file qvariant.cpp.
QSizeF QVariant::toSizeF | ( | ) | const |
Returns the variant as a QSizeF if the variant has userType() \l QMetaType::QSizeF; otherwise returns an invalid QSizeF.
Definition at line 1573 of file qvariant.cpp.
QString QVariant::toString | ( | ) | const |
Returns the variant as a QString if the variant has a userType() including, but not limited to:
\l QMetaType::QString, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::QDate, \l QMetaType::QDateTime, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QStringList, \l QMetaType::QTime, \l QMetaType::UInt, or \l QMetaType::ULongLong.
Calling QVariant::toString() on an unsupported variant returns an empty string.
Definition at line 1416 of file qvariant.cpp.
QStringList QVariant::toStringList | ( | ) | const |
Returns the variant as a QStringList if the variant has userType() \l QMetaType::QStringList, \l QMetaType::QString, or \l QMetaType::QVariantList of a type that can be converted to QString; otherwise returns an empty list.
Definition at line 1396 of file qvariant.cpp.
QTime QVariant::toTime | ( | ) | const |
Returns the variant as a QTime if the variant has userType() \l QMetaType::QTime, \l QMetaType::QDateTime, or \l QMetaType::QString; otherwise returns an invalid time.
If the type() is \l QMetaType::QString, an invalid time will be returned if the string cannot be parsed as a Qt::ISODate format time.
Definition at line 1472 of file qvariant.cpp.
Returns the variant as an unsigned int if the variant has userType() \l QMetaType::UInt, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, or \l QMetaType::ULongLong; otherwise returns 0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to an unsigned int; otherwise
{*}{ok} is set to false.
{Warning:} If the value is convertible to a \l QMetaType::ULongLong but is too large to be represented in an unsigned int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toUInt().
Definition at line 1855 of file qvariant.cpp.
qulonglong QVariant::toULongLong | ( | bool * | ok = nullptr | ) | const |
Returns the variant as an unsigned long long int if the variant has type() \l QMetaType::ULongLong, \l QMetaType::Bool, \l QMetaType::QByteArray, \l QMetaType::QChar, \l QMetaType::Double, \l QMetaType::Int, \l QMetaType::LongLong, \l QMetaType::QString, or \l QMetaType::UInt; otherwise returns 0.
If ok is non-null: {*}{ok} is set to true if the value could be converted to an int; otherwise
{*}{ok} is set to false.
Definition at line 1889 of file qvariant.cpp.
QUrl QVariant::toUrl | ( | ) | const |
Returns the variant as a QUrl if the variant has userType() \l QMetaType::QUrl; otherwise returns an invalid QUrl.
Definition at line 1643 of file qvariant.cpp.
QUuid QVariant::toUuid | ( | ) | const |
Returns the variant as a QUuid if the variant has type() \l QMetaType::QUuid, \l QMetaType::QByteArray or \l QMetaType::QString; otherwise returns a default-constructed QUuid.
Definition at line 1715 of file qvariant.cpp.
|
inline |
Returns the storage type of the value stored in the variant. This is the same as metaType().id().
Definition at line 241 of file qvariant.h.
const char * QVariant::typeName | ( | ) | const |
Returns the name of the type stored in the variant. The returned strings describe the C++ datatype used to store the data: for example, "QFont", "QString", or "QVariantList". An Invalid variant returns 0.
Definition at line 1073 of file qvariant.cpp.
|
inline |
Returns the stored value converted to the template type {T}. Call canConvert() to find out whether a type can be converted. If the value cannot be converted, a \l{default-constructed value} will be returned.
If the type {T} is supported by QVariant, this function behaves exactly as toString(), toInt() etc.
Example:
If the QVariant contains a pointer to a type derived from QObject then {T} may be any QObject type. If the pointer stored in the QVariant can be qobject_cast to T, then that result is returned. Otherwise \nullptr is returned. Note that this only works for QObject subclasses which use the Q_OBJECT macro.
If the QVariant contains a sequential container and {T} is QVariantList, the elements of the container will be converted into \l {QVariant}s and returned as a QVariantList.
Definition at line 378 of file qvariant.h.
Returns a mutable view of template type {T} on the stored value. Call canView() to find out whether such a view is supported. If no such view can be created, returns the stored value converted to the template type
{T}. Call canConvert() to find out whether a type can be converted. If the value can neither be viewed nor converted, a \l{default-constructed value} will be returned.
Definition at line 382 of file qvariant.h.
|
protected |
Definition at line 2083 of file qvariant.cpp.
|
friend |
Returns false
if v1 and v2 are equal; otherwise returns true
.
QVariant uses the equality operator of the type() contained to check for equality.
Variants of different types will always compare as not equal with a few exceptions:
\list
Definition at line 521 of file qvariant.h.
|
friend |
Definition at line 525 of file qvariant.h.
Returns true
if v1 and v2 are equal; otherwise returns false
.
QVariant uses the equality operator of the type() contained to check for equality.
Variants of different types will always compare as not equal with a few exceptions:
\list
The result of the function is not affected by the result of QVariant::isNull, which means that two values can be equal even if one of them is null and another is not.
Definition at line 519 of file qvariant.h.
Returns the given value converted to the template type {T}.
This function is equivalent to QVariant::value().
Definition at line 620 of file qvariant.h.
Returns true
if the given value can be converted to the template type specified; otherwise returns false
.
This function is equivalent to QVariant::canConvert(value).
|
related |
|
related |
Synonym for QList<QVariant>.
Definition at line 51 of file qjsonarray.h.
|
related |
Synonym for QMap<QString, QVariant>.
Definition at line 75 of file qcontainerfwd.h.
Returns the given value converted to the template type {T}.
This function is equivalent to \l{QVariant::value()}{QVariant::value}<T>(value).
|
protected |
Definition at line 533 of file qvariant.h.