CopperSpice API
1.9.2
|
Stores a single value of almost any data type. More...
Public Types | |
enum | Type : uint |
Public Methods | |
QVariant () | |
QVariant (bool value) | |
QVariant (const QVariant &other) | |
QVariant (double value) | |
QVariant (float value) | |
QVariant (int value) | |
QVariant (QBitArray value) | |
QVariant (QByteArray value) | |
QVariant (QChar32 value) | |
QVariant (QDataStream &stream) | |
QVariant (QDate value) | |
QVariant (QDateTime value) | |
QVariant (QEasingCurve value) | |
QVariant (QHash< QString, QVariant > value) | |
QVariant (qint64 value) | |
QVariant (QJsonArray value) | |
QVariant (QJsonDocument value) | |
QVariant (QJsonObject value) | |
QVariant (QJsonValue value) | |
QVariant (QLine value) | |
QVariant (QLineF value) | |
QVariant (QList< QVariant > value) | |
QVariant (QLocale value) | |
QVariant (QMap< QString, QVariant > value) | |
QVariant (QModelIndex value) | |
QVariant (QMultiHash< QString, QVariant > value) | |
QVariant (QMultiMap< QString, QVariant > value) | |
QVariant (QPersistentModelIndex value) | |
QVariant (QPoint value) | |
QVariant (QPointF value) | |
QVariant (QRect value) | |
QVariant (QRectF value) | |
QVariant (QRegularExpression8 value) | |
QVariant (QSize value) | |
QVariant (QSizeF value) | |
QVariant (QString value) | |
QVariant (QString16 value) | |
QVariant (QStringList value) | |
QVariant (QTime value) | |
QVariant (quint64 value) | |
QVariant (QUrl value) | |
QVariant (QUuid value) | |
QVariant (QVariant &&other) = default | |
QVariant (Type type) | |
QVariant (uint typeId, const void *copy) | |
QVariant (uint value) | |
~QVariant () = default | |
template<typename T > | |
bool | canConvert () const |
bool | canConvert (uint newType) const |
void | clear () |
template<typename T > | |
bool | convert () |
bool | convert (uint newType) |
int64_t | enumToInt () const |
uint64_t | enumToUInt () const |
template<typename T > | |
T | getData () const |
template<typename T > | |
std::optional< T > | getDataOr () const |
bool | isEnum () const |
bool | isValid () const |
std::optional< QVariant > | maybeConvert (uint requested_type) const |
bool | operator!= (const QVariant &other) const |
QVariant & | operator= (const QVariant &other) |
QVariant & | operator= (QVariant &&other) |
bool | operator== (const QVariant &other) const |
void | setValue (const QVariant &value) |
template<typename T > | |
void | setValue (const T &value) |
void | swap (QVariant &other) |
QBitArray | toBitArray () const |
bool | toBool (bool *ok=nullptr) const |
QByteArray | toByteArray () const |
QChar32 | toChar () const |
QDate | toDate () const |
QDateTime | toDateTime () const |
double | toDouble (bool *ok=nullptr) const |
QEasingCurve | toEasingCurve () const |
float | toFloat (bool *ok=nullptr) const |
QHash< QString, QVariant > | toHash () const |
int | toInt (bool *ok=nullptr) const |
QJsonArray | toJsonArray () const |
QJsonDocument | toJsonDocument () const |
QJsonObject | toJsonObject () const |
QJsonValue | toJsonValue () const |
QLine | toLine () const |
QLineF | toLineF () const |
QList< QVariant > | toList () const |
QLocale | toLocale () const |
qint64 | toLongLong (bool *ok=nullptr) const |
QMap< QString, QVariant > | toMap () const |
QModelIndex | toModelIndex () const |
QMultiHash< QString, QVariant > | toMultiHash () const |
QMultiMap< QString, QVariant > | toMultiMap () const |
QPersistentModelIndex | toPersistentModelIndex () const |
QPoint | toPoint () const |
QPointF | toPointF () const |
qreal | toReal (bool *ok=nullptr) const |
QRect | toRect () const |
QRectF | toRectF () const |
QRegularExpression8 | toRegularExpression () const |
QSize | toSize () const |
QSizeF | toSizeF () const |
QString8 | toString () const |
QString16 | toString16 () const |
QStringList | toStringList () const |
QTime | toTime () const |
uint | toUInt (bool *ok=nullptr) const |
quint64 | toULongLong (bool *ok=nullptr) const |
QUrl | toUrl () const |
QUuid | toUuid () const |
Type | type () const |
QString | typeName () const |
uint | userType () const |
template<typename Requested > | |
Requested | value () const |
Static Public Methods | |
static QVariant | fromValue (const QVariant &value) |
template<typename T > | |
static QVariant | fromValue (const T &value) |
static uint | nameToType (const QString &name) |
static QString | typeToName (uint typeId) |
template<typename T > | |
static uint | typeToTypeId () |
Related Functions | |
These are not member functions | |
#define | CS_DECLARE_METATYPE(TYPE) |
bool | operator!= (const QVariant &v1, const QVariant &v2) |
QDataStream & | operator<< (QDataStream &stream, QVariant &data) |
bool | operator== (const QVariant &v1, const QVariant &v2) |
QDataStream & | operator>> (QDataStream &stream, const QVariant &data) |
T | qvariant_cast (const QVariant &x) |
QVariantHash | |
QVariantList | |
QVariantMap | |
The QVariant class is used to store a single value of some other data type. Not every value can be stored in a QVariant using every data type. For example, a QString can be retrieved as QKeySequence but it can not be retrieved as a QPoint. The QObject::property() system relies on the enums, methods, and data storage which is provided by this class.
The data stored in a QVariant has a corresponding integer type id which is defined in the QVariant::Type enum. If there is no match then the integer type id is represented by the value QVariant::Type::UserType.
The QVariant::Type enum contains a list of the CsCore and CsGui data types most often associated with variants. QVariant can be extended to support other data types by calling the CS_DECLARE_METATYPE() macro.
An important feature of the property system is the ability to provide a string representation for a given data type. For example, given the data type QStringList the string representation would be "QStringList" and for a bool the string representation would be "bool". To retrieve this string call typeName() on an existing QVariant object.
To find the integer type id which corresponds to a given data type name use the method nameToType().
There are five QVariant types which can be used to represent a container of QVariants. This allows storing complex data structures of arbitrary types. Although this is a useful feature and very convenient, it may be less efficient than storing the data in a standard strongly typed container.
There are a variety of methods which begin with the name "to" and are used to convert a variant value to the requested type. For example toString(), toDate(), or toInt() are methods to convert the variant to a QString, QDate, and an integer respectively. The returned value will be a copy even if no conversion occurs. If the conversion fails the return value will be an empty, null, or zero based on the requested type.
The following example shows several ways to use a QVariant.
QVariant is part of the CsCore library and can not provide conversion functions to data types defined in another library such as CsGui. This means you will not find a toColor() method to convert a QVariant value to a QColor.
The correct way to accomplish this is by using the templated value() method.
Converting from a QColor to a QVariant is automatic for data types which are supported by QVariant.
To find out what data type the QVariant holds use the type() method and to convert the object to a different type use convert().
To verify if a given object can be converted to a different type, use canConvert(). It is possible for canConvert() to return true, but then convert() will return false. This happens because canConvert() only looks at the source and target data types, not the actual values.
For example, canConvert(Type::Int) will return true when called on a variant which contains a string. Passing this enum asks if the string can be converted to an int, which is valid. However, if the string contains non-numeric characters it can not be converted to an integer, so convert() will fail.
enum QVariant::Type : uint |
This enum type defines the types of variable that a QVariant can contain.
Constant | Description |
---|---|
QVariant::Invalid | Invalid data type |
QVariant::BitArray | QBitArray |
QVariant::Bitmap | QBitmap |
QVariant::Bool | bool |
QVariant::Brush | QBrush |
QVariant::ByteArray | QByteArray |
QVariant::Char | QChar |
QVariant::Char32 | QChar32 |
QVariant::Color | QColor |
QVariant::Cursor | QCursor |
QVariant::Date | QDate |
QVariant::DateTime | QDateTime |
QVariant::Double | double |
QVariant::EasingCurve | QEasingCurve |
QVariant::Font | QFont |
QVariant::Hash | QVariantHash |
QVariant::Icon | QIcon |
QVariant::Image | QImage |
QVariant::Int | int |
QVariant::KeySequence | QKeySequence |
QVariant::Line | QLine |
QVariant::LineF | QLineF |
QVariant::List | QVariantList |
QVariant::Locale | QLocale |
QVariant::LongLong | long long |
QVariant::Map | QVariantMap |
QVariant::Matrix | QMatrix |
QVariant::Transform | QTransform |
QVariant::Matrix4x4 | QMatrix4x4 |
QVariant::Palette | QPalette |
QVariant::Pen | QPen |
QVariant::Pixmap | QPixmap |
QVariant::Point | QPoint |
QVariant::PointF | QPointF |
QVariant::Polygon | QPolygon |
QVariant::Quaternion | QQuaternion |
QVariant::Rect | QRect |
QVariant::RectF | QRectF |
QVariant::RegularExpression | QRegularExpression |
QVariant::Region | QRegion |
QVariant::Size | QSize |
QVariant::SizeF | QSizeF |
QVariant::SizePolicy | QSizePolicy |
QVariant::String | QString |
QVariant::String8 | QString8 |
QVariant::String16 | QString16 |
QVariant::StringList | QStringList |
QVariant::TextFormat | QTextFormat |
QVariant::TextLength | QTextLength |
QVariant::Time | QTime |
QVariant::UInt | uint |
QVariant::ULongLong | quint64 |
QVariant::Url | QUrl |
QVariant::Vector2D </td | QVector2D |
QVariant::Vector3D | QVector3D |
QVariant::Vector4D | QVector4D |
QVariant::UserType | Base value for user defined types |
|
inline |
Constructs an empty QVariant.
QVariant::QVariant | ( | Type | type | ) |
Constructs a empty variant with the data type of type.
QVariant::QVariant | ( | uint | typeId, |
const void * | copy | ||
) |
Constructs a variant with of a type of typeId and initializes with copy, if the copy is not a null pointer. Ensure you pass the address of the variable you want stored.
This constructor in seldom used. The QVariant::fromValue() method should be used instead to construct variants from the pointer types represented by VoidStar
, QObjectStar
and QWidgetStar
.
QVariant::QVariant | ( | const QVariant & | other | ) |
Copy constructs a new QVariant from other.
|
default |
Move constructs a new QVariant from other.
QVariant::QVariant | ( | bool | value | ) |
Constructs a new variant with a boolean of value.
QVariant::QVariant | ( | int | value | ) |
Constructs a new variant with an integer of value.
QVariant::QVariant | ( | uint | value | ) |
Constructs a new variant with an unsigned integer of value.
QVariant::QVariant | ( | double | value | ) |
Constructs a new variant with a floating point of value.
QVariant::QVariant | ( | float | value | ) |
Constructs a new variant with a floating point of value.
QVariant::QVariant | ( | QByteArray | value | ) |
Constructs a new variant with a QByteArray of value.
QVariant::QVariant | ( | QStringList | value | ) |
Constructs a new variant with a QStringList of value.
QVariant::QVariant | ( | QRegularExpression8 | value | ) |
Constructs a new variant with a QRegularExpression of value.
QVariant::QVariant | ( | QList< QVariant > | value | ) |
Constructs a new variant with a list of QVariants contained of value.
Constructs a new variant with a hash of QVariants contained of value.
Constructs a new variant with a map of QVariants contained of value.
QVariant::QVariant | ( | QMultiHash< QString, QVariant > | value | ) |
Constructs a new variant with a multi hash of value.
Constructs a new variant with a multi map of value.
QVariant::QVariant | ( | QJsonValue | value | ) |
Constructs a new variant with a QJsonValue of value.
QVariant::QVariant | ( | QJsonObject | value | ) |
Constructs a new variant with a QJsonObject of value.
QVariant::QVariant | ( | QJsonArray | value | ) |
Constructs a new variant with a QJsonArray of value.
QVariant::QVariant | ( | QJsonDocument | value | ) |
Constructs a new variant with a QJsonDocument of value.
QVariant::QVariant | ( | QEasingCurve | value | ) |
Constructs a new variant with an QEasingCurve of value.
QVariant::QVariant | ( | QModelIndex | value | ) |
Constructs a new variant with a QModelIndex of value.
QVariant::QVariant | ( | QPersistentModelIndex | value | ) |
Constructs a new variant with a QPersistentModelIndex of value.
QVariant::QVariant | ( | QDataStream & | stream | ) |
Reads the variant from the data given stream.
|
default |
Destroys the QVariant and the contained object.
|
inline |
bool QVariant::canConvert | ( | uint | newType | ) | const |
Returns true if the current variant type can be cast to the requested variant newType. It is possible for this method to return true, but then convert() will return false. This happens because this method only looks at the source and target data types, not the actual values.
Current Type | Requested Type |
---|---|
Bitmap | Image, Pixmap |
Bool | ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Brush | Color, Pixmap |
ByteArray | Bool, Char, Color, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Char | Bool, ByteArray, Int, Long, LongLong, QChar, Short, SChar, UChar, UInt, ULong, ULongLong, UShort |
QChar | Bool, ByteArray, Char, Int, Long, LongLong, Short, SChar, String, String16, UChar, UInt, LongLong, ULong, ULongLong, UShort |
SChar | Bool, ByteArray, Char, Int, Long, LongLong, QChar, Short, UChar, UInt, ULong, ULongLong, UShort |
UChars | Bool, ByteArray, Char, Int, Long, LongLong, QChar, SChar, Short, UInt, ULong, ULongLong, UShort |
Color | Brush, ByteArray, String, String16 |
Date | DateTime, String, String16 |
DateTime | Date, String, String16, Time |
Double | Bool, ByteArray, Char, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Float | Bool, ByteArray, Char, Double, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Font | String, String16 |
Image | Bitmap, Pixmap |
Hash | Map |
Int | Bool, ByteArray, Char, Double, Float, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
JsonArray | List |
JsonObject | Hash, Map |
JsonValue | Bool, Char, Double, Float, Hash, Int, Long, LongLong, List, Map, QChar, Short, SChar, String, String16, UChar, UInt, ULong, ULongLong, UShort |
KeySequence | String, String16 |
Line | LineF |
LineF | Line |
List | StringList Note: Conversion is only valid when the items in the List can be converted to Strings |
Long | Bool, ByteArray, Char, Double, Float, Int, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
LongLong | Bool, ByteArray, Char, Double, Float, Int, Long, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Map | Hash |
ModelIndex | PersistentModelIndex |
PersistentModelIndex | ModelIndex |
Pixmap | Bitmap, Brush, Image |
Point | PointF |
PointF | Point |
Rect | RectF |
RectF | Rect |
Short | Bool, ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, String, String16, UChar, UInt, ULong, ULongLong, UShort |
Size | SizeF |
SizeF | Size |
String, String16 | Bool, ByteArray, Char, Color, Date, DateTime, Double, Float, Font, Int, KeySequence, Long, LongLong, QChar, SChar, Short, StringList, Time, UChar, UInt, ULong, ULongLong, Url, UShort, Uuid |
StringList | List, String, String16 Note: Conversions to Strings are only valid when the StringList contains exactly one item |
Time | String, String16 |
UInt | Bool, ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, ULong, ULongLong, UShort |
ULong | Bool, ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULongLong, UShort |
ULongLong | Bool, ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, UShort |
UShort | Bool, ByteArray, Char, Double, Float, Int, Long, LongLong, QChar, SChar, Short, String, String16, UChar, UInt, ULong, ULongLong |
Url | ByteArray, String, String16 |
Uuid | ByteArray, String, String16 |
void QVariant::clear | ( | ) |
Sets this variant to an invalid data type and the integer type id to zero, which is the enum value QVariant::Invalid.
|
inline |
Casts the variant to the requested type T. If the conversion can not be done the variant is set to an invalid data type and the enum type is set to QVariant::Invalid.
Returns true if the variant was successfully converted, otherwise returns false.
bool QVariant::convert | ( | uint | newType | ) |
Casts the variant to the requested type newType. If the conversion can not be done the variant is set to an invalid data type and the enum type is set to QVariant::Invalid.
Returns true if the variant was successfully converted, otherwise returns false.
int64_t QVariant::enumToInt | ( | ) | const |
If the current QVariant contains a value which is an enum or a flag this method will return the value as a signed integer. Otherwise returns the value 0.
uint64_t QVariant::enumToUInt | ( | ) | const |
If the current QVariant contains a value which is an enum or a flag this method will return the value as an unsigned integer. Otherwise returns the value 0.
|
inlinestatic |
Returns a QVariant containing a copy of value. This is the same as calling setValue() on a new QVariant.
|
inlinestatic |
Returns a QVariant containing a copy of value. This is the same as calling setValue() on a new QVariant.
T QVariant::getData | ( | ) | const |
Returns the value for this QVariant if the data type of the QVariant matches T. Otherwise returns a default constructed T.
std::optional< T > QVariant::getDataOr | ( | ) | const |
Returns the value in this QVariant if the type is T. Otherwise this method returns an empty std::optional of type T.
bool QVariant::isEnum | ( | ) | const |
Returns true if the current QVariant contains a value which is an enum or a flag.
|
inline |
Returns true if the data type in this variant is not QVariant::Invalid, otherwise returns false.
std::optional< QVariant > QVariant::maybeConvert | ( | uint | requested_type | ) | const |
Returns an std::optional containing the value of this QVariant converted to the requested_type or an empty optional if the conversion fails.
Converts the data type specified by name, to the corresponding integer type id. If the name can not be converted the return value is zero.
|
inline |
Compares this QVariant with other and returns true if they are not equal, otherwise returns false.
QVariant & QVariant::operator= | ( | const QVariant & | other | ) |
Copy assigns from other and returns a reference to this object.
|
inline |
Move assigns from other and returns a reference to this object.
|
inline |
Compares this QVariant with other and returns true if they are equal, otherwise returns false. In the case of custom types, their equality operators are not called. Instead their addresses are compared.
|
inline |
Copies the data in value into this QVariant.
void QVariant::setValue | ( | const T & | value | ) |
Copies value into this QVariant.
|
inline |
Swaps variant other with this variant. This operation is very fast and never fails.
QBitArray QVariant::toBitArray | ( | ) | const |
Returns the variant as a QBitArray if the variant has a data type of BitArray, otherwise returns an empty QBitArray.
bool QVariant::toBool | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a bool if the variant has a data type of Bool.
Returns true if the variant has a data type of Bool, Char, Double, Int, LongLong, UInt, or ULongLong and the value is non-zero, or if the variant has type String or ByteArray and its lower case content is not empty, "0" or "false", otherwise returns false.
QByteArray QVariant::toByteArray | ( | ) | const |
Returns the variant as a QByteArray if the variant has a data type of ByteArray or String, otherwise returns an empty byte array.
QChar32 QVariant::toChar | ( | ) | const |
Returns the variant as a QChar32 if the variant has a data type of QChar, Char, Int, or UInt. If the conversion fails it returns a null QChar32.
QDate QVariant::toDate | ( | ) | const |
Returns the variant as a QDate if the variant has a data type of Date, DateTime, or String, otherwise returns an invalid date. If the type() is String, an invalid date will be returned if the string can not be parsed as a Qt::ISODate format date.
QDateTime QVariant::toDateTime | ( | ) | const |
Returns the variant as a QDateTime if the variant has a data type of DateTime, Date, or String, otherwise returns an invalid date/time.
If the type() is String, an invalid date/time will be returned if the string can not be parsed as a Qt::ISODate format date/time.
double QVariant::toDouble | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a double if the variant has a data type of Double, Float, Bool, ByteArray, Int, LongLong, String, UInt, or ULongLong, otherwise returns 0.0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QEasingCurve QVariant::toEasingCurve | ( | ) | const |
Returns the variant as a QEasingCurve if the variant has a data type of EasingCurve, otherwise returns a default easing curve.
float QVariant::toFloat | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a float if the variant has a data type of Double, Float, Bool, ByteArray, Int, LongLong, String, UInt, or ULongLong, otherwise returns 0.0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
Returns the variant as a QHash<QString, QVariant> if the variant has a data type of Hash, otherwise returns an empty QHash.
int QVariant::toInt | ( | bool * | ok = nullptr | ) | const |
Returns the variant as an int if the variant has a data type of Int, Bool, ByteArray, Char, Double, LongLong, String, UInt, or ULongLong, otherwise return a value of 0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QJsonArray QVariant::toJsonArray | ( | ) | const |
Returns the variant as a QJsonArray if the variant has a data type of JsonArray, otherwise returns a default constructed QJsonArray.
QJsonDocument QVariant::toJsonDocument | ( | ) | const |
Returns the variant as a QJsonDocument if the variant has a data type of JsonDocument, otherwise returns a default constructed QJsonDocument.
QJsonObject QVariant::toJsonObject | ( | ) | const |
Returns the variant as a QJsonObject if the variant has a data type of JsonObject, otherwise returns a default constructed QJsonObject.
QJsonValue QVariant::toJsonValue | ( | ) | const |
Returns the variant as a QJsonValue if the variant has a data type of JsonValue, otherwise returns a default constructed QJsonValue.
QLine QVariant::toLine | ( | ) | const |
Returns the variant as a QLine if the variant has a data type of Line, otherwise returns an invalid QLine.
QLineF QVariant::toLineF | ( | ) | const |
Returns the variant as a QLineF if the variant has a data type of LineF, otherwise returns an invalid QLineF.
QList< QVariant > QVariant::toList | ( | ) | const |
Returns the variant as a QVariantList if the variant has a data type of List or StringList, otherwise returns an empty list.
QLocale QVariant::toLocale | ( | ) | const |
Returns the variant as a QLocale if the variant has a data type of Locale, otherwise returns an invalid QLocale.
qint64 QVariant::toLongLong | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a qint64 integer if the variant has a data type of LongLong, Bool, ByteArray, Char, Double, Int, String, UInt, or ULongLong, otherwise returns 0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
Returns the variant as a QMap<QString, QVariant> if the variant has a data type of Map, otherwise returns an empty QMap.
QModelIndex QVariant::toModelIndex | ( | ) | const |
Returns the variant as a QModelIndex if the variant has a data type of ModelIndex, otherwise returns a default constructed QModelIndex.
QMultiHash< QString, QVariant > QVariant::toMultiHash | ( | ) | const |
Returns the variant as a QMultiHash<QString, QVariant> if the variant has a data type of MultiHash, otherwise returns an empty multi QMultiHash.
Returns the variant as a QMultiMap<QString, QVariant> if the variant has a data type of MultiMap, otherwise returns an empty multi QMultiMap.
QPersistentModelIndex QVariant::toPersistentModelIndex | ( | ) | const |
Returns the variant as a QPersistentModelIndex if the variant has a data type of PersistentModelIndex, otherwise returns a default constructed QPersistentModelIndex.
QPoint QVariant::toPoint | ( | ) | const |
Returns the variant as a QPoint if the variant has a data type of Point or PointF, otherwise returns a null QPoint.
QPointF QVariant::toPointF | ( | ) | const |
Returns the variant as a QPointF if the variant has a data type of Point or PointF, otherwise returns a null QPointF.
qreal QVariant::toReal | ( | bool * | ok = nullptr | ) | const |
Returns the variant as a qreal if the variant has a data type of Double, Float, Bool, ByteArray, Int, LongLong, String, UInt, or ULongLong, otherwise returns 0.0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QRect QVariant::toRect | ( | ) | const |
Returns the variant as a QRect if the variant has a data type of Rect, otherwise returns an invalid QRect.
QRectF QVariant::toRectF | ( | ) | const |
Returns the variant as a QRectF if the variant has a data type of Rect or RectF, otherwise returns an invalid QRectF.
QRegularExpression8 QVariant::toRegularExpression | ( | ) | const |
Returns the variant as a QRegularExpression8 if the variant has a data type of RegularExpression otherwise returns an empty QRegularExpression8.
QSize QVariant::toSize | ( | ) | const |
Returns the variant as a QSize if the variant has a data type of Size, otherwise returns an invalid QSize.
QSizeF QVariant::toSizeF | ( | ) | const |
Returns the variant as a QSizeF if the variant has a data type of SizeF, otherwise returns an invalid QSizeF.
QString8 QVariant::toString | ( | ) | const |
Returns the variant as a QString8 if the variant has a data type of String, Bool, ByteArray, Char, QDate, DateTime, Double, Int, LongLong, StringList, Time, UInt, or ULongLong, otherwise returns an empty string.
QString16 QVariant::toString16 | ( | ) | const |
Returns the variant as a QString16 if the variant has a data type of String, Bool, ByteArray, Char, Date, DateTime, Double, Int, LongLong, QStringList, Time, UInt, or ULongLong, otherwise returns an empty string.
QStringList QVariant::toStringList | ( | ) | const |
Returns the variant as a QStringList if the variant has a data type of StringList, String, or List of a type that can be converted to QString, otherwise returns an empty list.
QTime QVariant::toTime | ( | ) | const |
Returns the variant as a QTime if the variant has a data type of Time, DateTime, or String, otherwise returns an invalid time. If the type() is QString, an invalid time will be returned if the string can not be parsed as a Qt::ISODate format time.
uint QVariant::toUInt | ( | bool * | ok = nullptr | ) | const |
Returns the variant as an unsigned integer if the variant has a data type of UInt, Bool, ByteArray, Char, Double, Int, LongLong, String, or ULongLong, otherwise returns 0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
quint64 QVariant::toULongLong | ( | bool * | ok = nullptr | ) | const |
Returns the variant as an quint64 integer if the variant has a data type of ULongLong, Bool, ByteArray, Char, Double, Int, LongLong, String, or UInt, otherwise returns 0. If ok is not a nullptr, this method will set the value according to the success of the conversion. The value is false to indicate the conversion failed, otherwise ok is set to true.
QUrl QVariant::toUrl | ( | ) | const |
Returns the variant as a QUrl if the variant has a data type of Url, otherwise returns an invalid QUrl.
QUuid QVariant::toUuid | ( | ) | const |
Returns the variant as a QUuid if the variant has a data type of Uuid or String, otherwise returns a default constructed QUuid.
Type QVariant::type | ( | ) | const |
Returns the enum value corresponding to the data type which is currently stored in this variant. Returns QVariant::UserType if the data type is not one of the pre-defined types.
QString QVariant::typeName | ( | ) | const |
Returns the name of the data type or class stored in the variant. For example, for the class QFont this method will return "QFont". For primitive types like bool this method will return "bool". If the variant is empty returns an empty string.
For user defined data types this method will return the name which was previously registered when CS_DECLARE_METATYPE() was called.
Converts the given integer type id typeId to the name of the corresponding data type. If the typeId is QVariant::Invalid this method returns an empty string.
|
inlinestatic |
Returns the integer type id corresponding to the template parameter T.
uint QVariant::userType | ( | ) | const |
Returns the integer type id for this variant. For non-user defined values, which are listed in the QVariant::Type enum, this method returns the same result as calling the type() method.
Requested QVariant::value | ( | ) | const |
Returns the value in this variant if it can be converted to the data type specified in the template parameter Requested.
Calling canConvert() will indicate whether the current type can be converted to a particular Requested type. If the value can not be converted, a default constructed value of type Requested will be returned.
|
related |
This macro makes the Type known to the Variant system. The Type being registered must have a public default constructor, a public copy constructor and a public destructor. It is recommended the Type should have and support an operator==() method.
This macro should be placed after the declaration of the class or struct, which is usually in the header file.
The following is an example of a typical use case.
If MyNewClass is located within a namespace the CS_DECLARE_METATYPE() macro needs to appear outside the namespace.
The following is an example of how to use MyNewClass in a QVariant.
|
related |
Returns false if v1 and v2 are equal, otherwise returns true.
|
related |
Writes the given data to the stream. Returns a reference to the stream.
|
related |
Returns true if v1 and v2 are equal, otherwise returns false.
|
related |
Reads from the stream into the given data. Returns a reference to the stream.
|
related |
|
related |
Equivalent to QHash<QString, QVariant>.
|
related |
Equivalent to QList<QVariant>.
|
related |
Equivalent to QMap<QString, QVariant>>.