Qt 4.8
Public Types | Public Functions | Static Public Functions | Protected Functions | Protected Variables | Static Protected Variables | Private Functions | Friends | Related Functions | List of all members
QVariant Class Reference

The QVariant class acts like a union for the most common Qt data types. More...

#include <qvariant.h>

Inheritance diagram for QVariant:
QDBusVariant

Public Types

typedef Private DataPtr
 
enum  Type {
  Invalid = 0, Bool = 1, Int = 2, UInt = 3,
  LongLong = 4, ULongLong = 5, Double = 6, Char = 7,
  Map = 8, List = 9, String = 10, StringList = 11,
  ByteArray = 12, BitArray = 13, Date = 14, Time = 15,
  DateTime = 16, Url = 17, Locale = 18, Rect = 19,
  RectF = 20, Size = 21, SizeF = 22, Line = 23,
  LineF = 24, Point = 25, PointF = 26, RegExp = 27,
  Hash = 28, EasingCurve = 29, LastCoreType = EasingCurve, Font = 64,
  Pixmap = 65, Brush = 66, Color = 67, Palette = 68,
  Icon = 69, Image = 70, Polygon = 71, Region = 72,
  Bitmap = 73, Cursor = 74, SizePolicy = 75, KeySequence = 76,
  Pen = 77, TextLength = 78, TextFormat = 79, Matrix = 80,
  Transform = 81, Matrix4x4 = 82, Vector2D = 83, Vector3D = 84,
  Vector4D = 85, Quaternion = 86, LastGuiType = Quaternion, UserType = 127,
  LastType = 0xffffffff
}
 This enum type defines the types of variable that a QVariant can contain. More...
 

Public Functions

bool canConvert (Type t) const
 Returns true if the variant's type can be cast to the requested type, t. More...
 
template<typename T >
bool canConvert () const
 Returns true if the variant can be converted to the template type T, otherwise false. More...
 
void clear ()
 Convert this variant to type Invalid and free up any resources used. More...
 
const void * constData () const
 
bool convert (Type t)
 Casts the variant to the requested type, t. More...
 
void * data ()
 
const void * data () const
 
DataPtrdata_ptr ()
 
void detach ()
 
bool isDetached () const
 
bool isNull () const
 Returns true if this is a NULL variant, false otherwise. More...
 
bool isValid () const
 Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false. More...
 
void load (QDataStream &ds)
 Internal function for loading a variant from stream s. More...
 
bool operator!= (const QVariant &v) const
 Compares this QVariant with v and returns true if they are not equal; otherwise returns false. More...
 
QVariantoperator= (const QVariant &other)
 Assigns the value of the variant variant to this variant. More...
 
bool operator== (const QVariant &v) const
 Compares this QVariant with v and returns true if they are equal; otherwise returns false. More...
 
 QVariant ()
 Constructs an invalid variant. More...
 
 QVariant (Type type)
 Constructs a null variant of type type. More...
 
 QVariant (int typeOrUserType, const void *copy)
 Constructs variant of type typeOrUserType, and initializes with copy if copy is not 0. More...
 
 QVariant (int typeOrUserType, const void *copy, uint flags)
 
 QVariant (const QVariant &other)
 Constructs a copy of the variant, p, passed as the argument to this constructor. More...
 
 QVariant (QDataStream &s)
 Reads the variant from the data stream, s. More...
 
 QVariant (int i)
 Constructs a new variant with an integer value, val. More...
 
 QVariant (uint ui)
 Constructs a new variant with an unsigned integer value, val. More...
 
 QVariant (qlonglong ll)
 Constructs a new variant with a long long integer value, val. More...
 
 QVariant (qulonglong ull)
 Constructs a new variant with an unsigned long long integer value, val. More...
 
 QVariant (bool b)
 Constructs a new variant with a boolean value, val. More...
 
 QVariant (double d)
 Constructs a new variant with a floating point value, val. More...
 
 QVariant (float f)
 Constructs a new variant with a floating point value, val. More...
 
QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant (const char *str)
 Constructs a new variant with a string value of val. More...
 
 QVariant (const QByteArray &bytearray)
 Constructs a new variant with a bytearray value, val. More...
 
 QVariant (const QBitArray &bitarray)
 Constructs a new variant with a bitarray value, val. More...
 
 QVariant (const QString &string)
 Constructs a new variant with a string value, val. More...
 
 QVariant (const QLatin1String &string)
 Constructs a new variant with a string value, val. More...
 
 QVariant (const QStringList &stringlist)
 Constructs a new variant with a string list value, val. More...
 
 QVariant (const QChar &qchar)
 Constructs a new variant with a char value, c. More...
 
 QVariant (const QDate &date)
 Constructs a new variant with a date value, val. More...
 
 QVariant (const QTime &time)
 Constructs a new variant with a time value, val. More...
 
 QVariant (const QDateTime &datetime)
 Constructs a new variant with a date/time value, val. More...
 
 QVariant (const QList< QVariant > &list)
 Constructs a new variant with a list value, val. More...
 
 QVariant (const QMap< QString, QVariant > &map)
 Constructs a new variant with a map of QVariants, val. More...
 
 QVariant (const QHash< QString, QVariant > &hash)
 Constructs a new variant with a hash of QVariants, val. More...
 
 QVariant (const QSize &size)
 Constructs a new variant with a size value of val. More...
 
 QVariant (const QSizeF &size)
 Constructs a new variant with a size value of val. More...
 
 QVariant (const QPoint &pt)
 Constructs a new variant with a point value of val. More...
 
 QVariant (const QPointF &pt)
 Constructs a new variant with a point value of val. More...
 
 QVariant (const QLine &line)
 Constructs a new variant with a line value of val. More...
 
 QVariant (const QLineF &line)
 Constructs a new variant with a line value of val. More...
 
 QVariant (const QRect &rect)
 Constructs a new variant with a rect value of val. More...
 
 QVariant (const QRectF &rect)
 Constructs a new variant with a rect value of val. More...
 
 QVariant (const QUrl &url)
 Constructs a new variant with a url value of val. More...
 
 QVariant (const QLocale &locale)
 Constructs a new variant with a locale value, l. More...
 
 QVariant (const QRegExp &regExp)
 Constructs a new variant with the regexp value regExp. More...
 
 QVariant (const QEasingCurve &easing)
 Constructs a new variant with an easing curve value, val. More...
 
 QVariant (Qt::GlobalColor color)
 Constructs a new variant of type QVariant::Color and initializes it with color. More...
 
void save (QDataStream &ds) const
 Internal function for saving a variant to the stream s. More...
 
template<typename T >
void setValue (const T &value)
 Stores a copy of value. More...
 
void swap (QVariant &other)
 Swaps variant other with this variant. More...
 
QBitArray toBitArray () const
 Returns the variant as a QBitArray if the variant has type() BitArray ; otherwise returns an empty bit array. More...
 
bool toBool () const
 Returns the variant as a bool if the variant has type() Bool. More...
 
QByteArray toByteArray () const
 Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QString::fromAscii()); otherwise returns an empty byte array. More...
 
QChar toChar () const
 Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an invalid QChar. More...
 
QDate toDate () const
 Returns the variant as a QDate if the variant has type() Date , DateTime , or String ; otherwise returns an invalid date. More...
 
QDateTime toDateTime () const
 Returns the variant as a QDateTime if the variant has type() DateTime , Date , or String ; otherwise returns an invalid date/time. More...
 
double toDouble (bool *ok=0) const
 Returns the variant as a double if the variant has type() Double , QMetaType::Float , Bool , ByteArray , Int , LongLong , String , UInt , or ULongLong ; otherwise returns 0.0. More...
 
QEasingCurve toEasingCurve () const
 Returns the variant as a QEasingCurve if the variant has type() EasingCurve ; otherwise returns a default easing curve. More...
 
float toFloat (bool *ok=0) const
 Returns the variant as a float if the variant has type() Double , QMetaType::Float , Bool , ByteArray , Int , LongLong , String , UInt , or ULongLong ; otherwise returns 0.0. More...
 
QHash< QString, QVarianttoHash () const
 Returns the variant as a QHash<QString, QVariant> if the variant has type() Hash ; otherwise returns an empty map. More...
 
int toInt (bool *ok=0) const
 Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char , Double , LongLong , String , UInt , or ULongLong ; otherwise returns 0. More...
 
QLine toLine () const
 Returns the variant as a QLine if the variant has type() Line ; otherwise returns an invalid QLine. More...
 
QLineF toLineF () const
 Returns the variant as a QLineF if the variant has type() LineF ; otherwise returns an invalid QLineF. More...
 
QList< QVarianttoList () const
 Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise returns an empty list. More...
 
QLocale toLocale () const
 Returns the variant as a QLocale if the variant has type() Locale ; otherwise returns an invalid QLocale. More...
 
qlonglong toLongLong (bool *ok=0) const
 Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0. More...
 
QMap< QString, QVarianttoMap () const
 Returns the variant as a QMap<QString, QVariant> if the variant has type() Map ; otherwise returns an empty map. More...
 
QPoint toPoint () const
 Returns the variant as a QPoint if the variant has type() Point or PointF ; otherwise returns a null QPoint. More...
 
QPointF toPointF () const
 Returns the variant as a QPointF if the variant has type() Point or PointF ; otherwise returns a null QPointF. More...
 
qreal toReal (bool *ok=0) const
 Returns the variant as a qreal if the variant has type() Double , QMetaType::Float , Bool , ByteArray , Int , LongLong , String , UInt , or ULongLong ; otherwise returns 0.0. More...
 
QRect toRect () const
 Returns the variant as a QRect if the variant has type() Rect ; otherwise returns an invalid QRect. More...
 
QRectF toRectF () const
 Returns the variant as a QRectF if the variant has type() Rect or RectF ; otherwise returns an invalid QRectF. More...
 
QRegExp toRegExp () const
 Returns the variant as a QRegExp if the variant has type() RegExp ; otherwise returns an empty QRegExp. More...
 
QSize toSize () const
 Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize. More...
 
QSizeF toSizeF () const
 Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF. More...
 
QString toString () const
 Returns the variant as a QString if the variant has type() String , Bool , ByteArray , Char , Date , DateTime , Double , Int , LongLong , StringList , Time , UInt , or ULongLong ; otherwise returns an empty string. More...
 
QStringList toStringList () const
 Returns the variant as a QStringList if the variant has type() StringList, String , or List of a type that can be converted to QString; otherwise returns an empty list. More...
 
QTime toTime () const
 Returns the variant as a QTime if the variant has type() Time , DateTime , or String ; otherwise returns an invalid time. More...
 
uint toUInt (bool *ok=0) const
 Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray , Char , Double , Int , LongLong , String , or ULongLong ; otherwise returns 0. More...
 
qulonglong toULongLong (bool *ok=0) const
 Returns the variant as as an unsigned long long int if the variant has type() ULongLong , Bool , ByteArray , Char , Double , Int , LongLong , String , or UInt ; otherwise returns 0. More...
 
QUrl toUrl () const
 Returns the variant as a QUrl if the variant has type() Url ; otherwise returns an invalid QUrl. More...
 
Type type () const
 Returns the storage type of the value stored in the variant. More...
 
const char * typeName () const
 Returns the name of the type stored in the variant. More...
 
int userType () const
 Returns the storage type of the value stored in the variant. More...
 
template<typename T >
value () const
 Returns the stored value converted to the template type T. More...
 
 ~QVariant ()
 Destroys the QVariant and the contained object. More...
 

Static Public Functions

template<typename T >
static QVariant fromValue (const T &value)
 Returns a QVariant containing a copy of value. More...
 
static Type nameToType (const char *name)
 Converts the string representation of the storage type given in name, to its enum representation. More...
 
static const char * typeToName (Type type)
 Converts the enum representation of the storage type, typ, to its string representation. More...
 

Protected Functions

bool cmp (const QVariant &other) const
 
void create (int type, const void *copy)
 

Protected Variables

Private d
 

Static Protected Variables

static const Handler * handler = &qt_kernel_variant_handler
 

Private Functions

 QVariant (void *)
 
 QVariant (bool, int)
 Use the QVariant(bool) constructor instead. More...
 

Friends

Q_CORE_EXPORT QDebug operator<< (QDebug, const QVariant &)
 
bool operator== (const QVariant &, const QVariantComparisonHelper &)
 
int qRegisterGuiVariant ()
 
int qUnregisterGuiVariant ()
 
bool qvariant_cast_helper (const QVariant &, QVariant::Type, void *)
 

Related Functions

(Note that these are not member functions.)

bool operator!= (const QVariant &v1, const QVariant &v2)
 Returns false if v1 and v2 are equal; otherwise returns true. More...
 
bool operator== (const QVariant &v1, const QVariant &v2)
 Returns true if v1 and v2 are equal; otherwise returns false. More...
 
qvariant_cast (const QVariant &value)
 Returns the given value converted to the template type T. More...
 
bool qVariantCanConvert (const QVariant &value)
 Returns true if the given value can be converted to the template type specified; otherwise returns false. More...
 
QVariant qVariantFromValue (const T &value)
 Returns a variant containing a copy of the given value with template type T. More...
 
 QVariantHash
 Synonym for QHash<QString, QVariant>. More...
 
 QVariantList
 Synonym for QList<QVariant>. More...
 
 QVariantMap
 Synonym for QMap<QString, QVariant>. More...
 
void qVariantSetValue (QVariant &variant, const T &value)
 Sets the contents of the given variant to a copy of the value with the specified template type T. More...
 
qVariantValue (const QVariant &value)
 Returns the given value converted to the template type T. More...
 

Detailed Description

The QVariant class acts like a union for the most common Qt data types.

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 type() at a time. (Some type()s 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:

QDataStream out(...);
QVariant v(123); // The variant now contains an int
int x = v.toInt(); // x = 123
out << v; // Writes a type tag and an int to out
v = QVariant("hello"); // The variant now contains a QByteArray
v = QVariant(tr("hello")); // The variant now contains a QString
int y = v.toInt(); // y = 0 since v cannot be converted to an int
QString s = v.toString(); // s = tr("hello") (see QObject::tr())
out << v; // Writes a type tag and a QString to out
...
QDataStream in(...); // (opening the previously written stream)
in >> v; // Reads an Int variant
int z = v.toInt(); // z = 123
qDebug("Type is %s", // prints "Type is int"
v.typeName());
v = v.toInt() + 100; // The variant now hold the value 223

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, where you can have a defined type with no value set. However, note that QVariant types can only be cast when they have had a value set.

QVariant x, y(QString()), z(QString(""));
// x.isNull() == true
// y.isNull() == true, z.isNull() == false

QVariant can be extended to support other types than those mentioned in the Type enum. See the QMetaType documentation for details.

A Note on GUI Types

Because QVariant is part of the QtCore library, it cannot provide conversion functions to data types defined in QtGui, such as QColor, QImage, and QPixmap. In other words, there is no toColor() function. Instead, you can use the QVariant::value() or the qvariant_cast() template function. For example:

...
QColor color = variant.value<QColor>();

The inverse conversion (e.g., from QColor to QVariant) is automatic for all data types supported by QVariant, including GUI-related types:

QColor color = palette().background().color();
QVariant variant = color;

()-and-convert()-Consecutively

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, canConvert() 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.

See also
QMetaType

Definition at line 92 of file qvariant.h.

Typedefs

◆ DataPtr

Warning
This function is not part of the public interface.

Definition at line 439 of file qvariant.h.

Enumerations

◆ Type

This enum type defines the types of variable that a QVariant can contain.

  • UserType Base value for user-defined types.
  • CString
  • ColorGroup
  • IconSet
  • LastGuiType
  • LastCoreType
  • LastType
Enumerator
Invalid 
Bool 
Int 
UInt 
LongLong 
ULongLong 
Double 
Char 
Map 
List 
String 
StringList 
ByteArray 
BitArray 
Date 
Time 
DateTime 
Url 
Locale 
Rect 
RectF 
Size 
SizeF 
Line 
LineF 
Point 
PointF 
RegExp 
Hash 
EasingCurve 
LastCoreType 
Font 
Pixmap 
Brush 
Color 
Palette 
Icon 
Image 
Polygon 
Region 
Bitmap 
Cursor 
SizePolicy 
KeySequence 
Pen 
TextLength 
TextFormat 
Matrix 
Transform 
Matrix4x4 
Vector2D 
Vector3D 
Vector4D 
Quaternion 
LastGuiType 
UserType 
LastType 

Definition at line 95 of file qvariant.h.

95  {
96  Invalid = 0,
97 
98  Bool = 1,
99  Int = 2,
100  UInt = 3,
101  LongLong = 4,
102  ULongLong = 5,
103  Double = 6,
104  Char = 7,
105  Map = 8,
106  List = 9,
107  String = 10,
108  StringList = 11,
109  ByteArray = 12,
110  BitArray = 13,
111  Date = 14,
112  Time = 15,
113  DateTime = 16,
114  Url = 17,
115  Locale = 18,
116  Rect = 19,
117  RectF = 20,
118  Size = 21,
119  SizeF = 22,
120  Line = 23,
121  LineF = 24,
122  Point = 25,
123  PointF = 26,
124  RegExp = 27,
125  Hash = 28,
126  EasingCurve = 29,
128 
129  // value 62 is internally reserved
130 #ifdef QT3_SUPPORT
131  ColorGroup = 63,
132 #endif
133  Font = 64,
134  Pixmap = 65,
135  Brush = 66,
136  Color = 67,
137  Palette = 68,
138  Icon = 69,
139  Image = 70,
140  Polygon = 71,
141  Region = 72,
142  Bitmap = 73,
143  Cursor = 74,
144  SizePolicy = 75,
145  KeySequence = 76,
146  Pen = 77,
147  TextLength = 78,
148  TextFormat = 79,
149  Matrix = 80,
150  Transform = 81,
151  Matrix4x4 = 82,
152  Vector2D = 83,
153  Vector3D = 84,
154  Vector4D = 85,
155  Quaternion = 86,
157 
158  UserType = 127,
159 #ifdef QT3_SUPPORT
160  IconSet = Icon,
161  CString = ByteArray,
162  PointArray = Polygon,
163 #endif
164  LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type
165  };
struct _XRegion * Region
Definition: qwindowdefs.h:118
ushort Char
The Transform elements provide a way of building advanced transformations on Items.
The Image element displays an image in a declarative user interface.

Constructors and Destructors

◆ QVariant() [1/41]

QVariant::QVariant ( )
inline

Constructs an invalid variant.

Definition at line 484 of file qvariant.h.

Referenced by save().

484 {}

◆ ~QVariant()

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 1427 of file qvariant.cpp.

1428 {
1429  if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared && d.type > Char && d.type < UserType))
1430  handler->clear(&d);
1431 }
static const Handler * handler
Definition: qvariant.h:419
ushort Char
Private d
Definition: qvariant.h:417

◆ QVariant() [2/41]

QVariant::QVariant ( Type  type)

Constructs a null variant of type type.

Definition at line 1788 of file qvariant.cpp.

1789 { create(type, 0); }
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901

◆ QVariant() [3/41]

QVariant::QVariant ( int  typeOrUserType,
const void *  copy 
)

Constructs variant of type typeOrUserType, and initializes with copy if copy is not 0.

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, QMetaType::QObjectStar and QMetaType::QWidgetStar.

See also
QVariant::fromValue(), Type

Definition at line 1790 of file qvariant.cpp.

1791 { create(typeOrUserType, copy); d.is_null = false; }
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
Private d
Definition: qvariant.h:417

◆ QVariant() [4/41]

QVariant::QVariant ( int  typeOrUserType,
const void *  copy,
uint  flags 
)
Warning
This function is not part of the public interface. flags is true if it is a pointer type

Definition at line 1796 of file qvariant.cpp.

1797 {
1798  if (flags) { //type is a pointer type
1799  d.type = typeOrUserType;
1800  d.data.ptr = *reinterpret_cast<void *const*>(copy);
1801  d.is_null = false;
1802  } else {
1803  create(typeOrUserType, copy);
1804  d.is_null = false;
1805  }
1806 }
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
Private d
Definition: qvariant.h:417

◆ QVariant() [5/41]

QVariant::QVariant ( const QVariant other)

Constructs a copy of the variant, p, passed as the argument to this constructor.

Definition at line 1443 of file qvariant.cpp.

1444  : d(p.d)
1445 {
1446  if (d.is_shared) {
1447  d.data.shared->ref.ref();
1448  } else if (p.d.type > Char && p.d.type < QVariant::UserType) {
1449  handler->construct(&d, p.constData());
1450  d.is_null = p.d.is_null;
1451  }
1452 }
static const Handler * handler
Definition: qvariant.h:419
ushort Char
Private d
Definition: qvariant.h:417

◆ QVariant() [6/41]

QVariant::QVariant ( QDataStream s)

Reads the variant from the data stream, s.

Definition at line 1458 of file qvariant.cpp.

1459 {
1460  d.is_null = true;
1461  s >> *this;
1462 }
Private d
Definition: qvariant.h:417

◆ QVariant() [7/41]

QVariant::QVariant ( int  i)

Constructs a new variant with an integer value, val.

Definition at line 1808 of file qvariant.cpp.

1809 { d.is_null = false; d.type = Int; d.data.i = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [8/41]

QVariant::QVariant ( uint  ui)

Constructs a new variant with an unsigned integer value, val.

Definition at line 1810 of file qvariant.cpp.

1811 { d.is_null = false; d.type = UInt; d.data.u = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [9/41]

QVariant::QVariant ( qlonglong  ll)

Constructs a new variant with a long long integer value, val.

Definition at line 1812 of file qvariant.cpp.

1813 { d.is_null = false; d.type = LongLong; d.data.ll = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [10/41]

QVariant::QVariant ( qulonglong  ull)

Constructs a new variant with an unsigned long long integer value, val.

Definition at line 1814 of file qvariant.cpp.

1815 { d.is_null = false; d.type = ULongLong; d.data.ull = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [11/41]

QVariant::QVariant ( bool  b)

Constructs a new variant with a boolean value, val.

Definition at line 1816 of file qvariant.cpp.

1817 { d.is_null = false; d.type = Bool; d.data.b = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [12/41]

QVariant::QVariant ( double  d)

Constructs a new variant with a floating point value, val.

Definition at line 1818 of file qvariant.cpp.

1819 { d.is_null = false; d.type = Double; d.data.d = val; }
Private d
Definition: qvariant.h:417

◆ QVariant() [13/41]

QVariant::QVariant ( float  val)
inline

Constructs a new variant with a floating point value, val.

Since
4.6

Definition at line 184 of file qvariant.h.

184 { d.is_null = false; d.type = QMetaType::Float; d.data.f = f; }
Private d
Definition: qvariant.h:417

◆ QVariant() [14/41]

QVariant::QVariant ( const char *  val)

Constructs a new variant with a string value of val.

The variant creates a deep copy of val, using the encoding set by QTextCodec::setCodecForCStrings().

Note that val is converted to a QString for storing in the variant and QVariant::type() will return QMetaType::QString for the variant.

You can disable this operator by defining QT_NO_CAST_FROM_ASCII when you compile your applications.

See also
QTextCodec::setCodecForCStrings()

Definition at line 1501 of file qvariant.cpp.

1502 {
1503  QString s = QString::fromAscii(val);
1504  create(String, &s);
1505 }
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
The QString class provides a Unicode character string.
Definition: qstring.h:83

◆ QVariant() [15/41]

QVariant::QVariant ( const QByteArray bytearray)

Constructs a new variant with a bytearray value, val.

Definition at line 1821 of file qvariant.cpp.

1822 { d.is_null = false; d.type = ByteArray; v_construct<QByteArray>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [16/41]

QVariant::QVariant ( const QBitArray bitarray)

Constructs a new variant with a bitarray value, val.

Definition at line 1823 of file qvariant.cpp.

1824 { d.is_null = false; d.type = BitArray; v_construct<QBitArray>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [17/41]

QVariant::QVariant ( const QString string)

Constructs a new variant with a string value, val.

Definition at line 1825 of file qvariant.cpp.

1826 { d.is_null = false; d.type = String; v_construct<QString>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [18/41]

QVariant::QVariant ( const QLatin1String string)

Constructs a new variant with a string value, val.

Definition at line 1829 of file qvariant.cpp.

1830 { QString str(val); d.is_null = false; d.type = String; v_construct<QString>(&d, str); }
The QString class provides a Unicode character string.
Definition: qstring.h:83
Private d
Definition: qvariant.h:417

◆ QVariant() [19/41]

QVariant::QVariant ( const QStringList stringlist)

Constructs a new variant with a string list value, val.

Definition at line 1831 of file qvariant.cpp.

1832 { d.is_null = false; d.type = StringList; v_construct<QStringList>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [20/41]

QVariant::QVariant ( const QChar qchar)

Constructs a new variant with a char value, c.

Definition at line 1827 of file qvariant.cpp.

1828 { d.is_null = false; d.type = Char; v_construct<QChar>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [21/41]

QVariant::QVariant ( const QDate date)

Constructs a new variant with a date value, val.

Definition at line 1834 of file qvariant.cpp.

1835 { d.is_null = false; d.type = Date; v_construct<QDate>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [22/41]

QVariant::QVariant ( const QTime time)

Constructs a new variant with a time value, val.

Definition at line 1836 of file qvariant.cpp.

1837 { d.is_null = false; d.type = Time; v_construct<QTime>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [23/41]

QVariant::QVariant ( const QDateTime datetime)

Constructs a new variant with a date/time value, val.

Definition at line 1838 of file qvariant.cpp.

1839 { d.is_null = false; d.type = DateTime; v_construct<QDateTime>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [24/41]

QVariant::QVariant ( const QList< QVariant > &  list)

Constructs a new variant with a list value, val.

Definition at line 1844 of file qvariant.cpp.

1845 { d.is_null = false; d.type = List; v_construct<QVariantList>(&d, list); }
Private d
Definition: qvariant.h:417

◆ QVariant() [25/41]

QVariant::QVariant ( const QMap< QString, QVariant > &  map)

Constructs a new variant with a map of QVariants, val.

Definition at line 1846 of file qvariant.cpp.

1847 { d.is_null = false; d.type = Map; v_construct<QVariantMap>(&d, map); }
QFuture< void > map(Sequence &sequence, MapFunction function)
Private d
Definition: qvariant.h:417

◆ QVariant() [26/41]

QVariant::QVariant ( const QHash< QString, QVariant > &  hash)

Constructs a new variant with a hash of QVariants, val.

Definition at line 1848 of file qvariant.cpp.

1849 { d.is_null = false; d.type = Hash; v_construct<QVariantHash>(&d, hash); }
static uint hash(const uchar *p, int n)
Definition: qhash.cpp:68
Private d
Definition: qvariant.h:417

◆ QVariant() [27/41]

QVariant::QVariant ( const QSize size)

Constructs a new variant with a size value of val.

Definition at line 1857 of file qvariant.cpp.

1857 { d.is_null = false; d.type = Size; v_construct<QSize>(&d, s); }
Private d
Definition: qvariant.h:417

◆ QVariant() [28/41]

QVariant::QVariant ( const QSizeF size)

Constructs a new variant with a size value of val.

Definition at line 1858 of file qvariant.cpp.

1858 { d.is_null = false; d.type = SizeF; v_construct<QSizeF>(&d, s); }
Private d
Definition: qvariant.h:417

◆ QVariant() [29/41]

QVariant::QVariant ( const QPoint pt)

Constructs a new variant with a point value of val.

Definition at line 1851 of file qvariant.cpp.

1851 { d.is_null = false; d.type = Point; v_construct<QPoint>(&d, pt); }
Private d
Definition: qvariant.h:417

◆ QVariant() [30/41]

QVariant::QVariant ( const QPointF pt)

Constructs a new variant with a point value of val.

Definition at line 1852 of file qvariant.cpp.

1852 { d.is_null = false; d.type = PointF; v_construct<QPointF>(&d, pt); }
Private d
Definition: qvariant.h:417

◆ QVariant() [31/41]

QVariant::QVariant ( const QLine line)

Constructs a new variant with a line value of val.

Definition at line 1855 of file qvariant.cpp.

1855 { d.is_null = false; d.type = Line; v_construct<QLine>(&d, l); }
Private d
Definition: qvariant.h:417
QFactoryLoader * l

◆ QVariant() [32/41]

QVariant::QVariant ( const QLineF line)

Constructs a new variant with a line value of val.

Definition at line 1854 of file qvariant.cpp.

1854 { d.is_null = false; d.type = LineF; v_construct<QLineF>(&d, l); }
Private d
Definition: qvariant.h:417
QFactoryLoader * l

◆ QVariant() [33/41]

QVariant::QVariant ( const QRect rect)

Constructs a new variant with a rect value of val.

Definition at line 1856 of file qvariant.cpp.

1856 { d.is_null = false; d.type = Rect; v_construct<QRect>(&d, r); }
Private d
Definition: qvariant.h:417

◆ QVariant() [34/41]

QVariant::QVariant ( const QRectF rect)

Constructs a new variant with a rect value of val.

Definition at line 1853 of file qvariant.cpp.

1853 { d.is_null = false; d.type = RectF; v_construct<QRectF>(&d, r); }
Private d
Definition: qvariant.h:417

◆ QVariant() [35/41]

QVariant::QVariant ( const QUrl url)

Constructs a new variant with a url value of val.

Definition at line 1861 of file qvariant.cpp.

1861 { d.is_null = false; d.type = Url; v_construct<QUrl>(&d, u); }
quint16 u
Private d
Definition: qvariant.h:417

◆ QVariant() [36/41]

QVariant::QVariant ( const QLocale locale)

Constructs a new variant with a locale value, l.

Definition at line 1863 of file qvariant.cpp.

1863 { d.is_null = false; d.type = Locale; v_construct<QLocale>(&d, l); }
Private d
Definition: qvariant.h:417
QFactoryLoader * l

◆ QVariant() [37/41]

QVariant::QVariant ( const QRegExp regExp)

Constructs a new variant with the regexp value regExp.

Definition at line 1865 of file qvariant.cpp.

1865 { d.is_null = false; d.type = RegExp; v_construct<QRegExp>(&d, regExp); }
Private d
Definition: qvariant.h:417

◆ QVariant() [38/41]

QVariant::QVariant ( const QEasingCurve val)

Constructs a new variant with an easing curve value, val.

Since
4.7

Definition at line 1841 of file qvariant.cpp.

1842 { d.is_null = false; d.type = EasingCurve; v_construct<QEasingCurve>(&d, val); }
Private d
Definition: qvariant.h:417

◆ QVariant() [39/41]

QVariant::QVariant ( Qt::GlobalColor  color)

Constructs a new variant of type QVariant::Color and initializes it with color.

Since
4.2

This is a convenience constructor that allows QVariant(Qt::blue); to create a valid QVariant storing a QColor.

Note: This constructor will assert if the application does not link to the Qt GUI library.

Definition at line 1867 of file qvariant.cpp.

1867 { create(62, &color); }
void create(int type, const void *copy)
Definition: qvariant.cpp:1407

◆ QVariant() [40/41]

QVariant::QVariant ( void *  )
inlineprivate

Definition at line 429 of file qvariant.h.

429 { Q_ASSERT(false); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

◆ QVariant() [41/41]

QVariant::QVariant ( bool  b,
int  dummy 
)
inlineprivate

Use the QVariant(bool) constructor instead.

Definition at line 436 of file qvariant.h.

436 { Q_ASSERT(false); }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823

Functions

◆ canConvert() [1/2]

bool QVariant::canConvert ( Type  t) const

Returns true if the variant's type can be cast to the requested type, t.

Such casting is done automatically when calling the toInt(), toBool(), ... methods.

The following casts are done automatically:

Type Automatically Cast To
Bool Char , Double , Int , LongLong , String , UInt , ULongLong
ByteArray Double , Int , LongLong , String , UInt , ULongLong
Char Bool , Int , UInt , LongLong , ULongLong
Color String
Date DateTime , String
DateTime Date , String , Time
Double Bool , Int , LongLong , String , UInt , ULongLong
Font String
Int Bool , Char , Double , LongLong , String , UInt , ULongLong
KeySequence Int , String
List StringList (if the list's items can be converted to strings)
LongLong Bool , ByteArray , Char , Double , Int , String , UInt , ULongLong
Point PointF
Rect RectF
String Bool , ByteArray , Char , Color , Date , DateTime , Double , Font , Int , KeySequence , LongLong , StringList , Time , UInt , ULongLong
StringList List , String (if the list contains exactly one item)
Time String
UInt Bool , Char , Double , Int , LongLong , String , ULongLong
ULongLong Bool , Char , Double , Int , LongLong , String , UInt
See also
convert()

Definition at line 2886 of file qvariant.cpp.

Referenced by QOCIResultPrivate::bindValue(), QScript::callQtMethod(), cmp(), convert(), QItemDelegate::drawBackground(), QOCICols::execBatch(), QHeaderViewPrivate::flipSortIndicator(), QComboMenuDelegate::getStyleOption(), QAbstractItemDelegate::helpEvent(), QStyledItemDelegate::initStyleOption(), QScriptEnginePrivate::jscValueToVariant(), operator>>(), QHeaderView::paintEvent(), QHeaderView::paintSection(), QDeclarativeObjectMethodScriptClass::property(), QVariantToVARIANT(), QHeaderView::sectionSizeFromContents(), QDeclarativeListAccessor::setList(), QItemDelegate::setOptions(), QVideoSurfaceFormat::setProperty(), QTest::toString(), QScript::variantFromValue(), QScript::variantProtoFuncToString(), VARIANTToQVariant(), and variantToString().

2887 {
2888  //we can treat floats as double
2889  //the reason for not doing it the "proper" way is that QMetaType::Float's value is 135,
2890  //which can't be handled by qCanConvertMatrix
2891  //In addition QVariant::Type doesn't have a Float value, so we're using QMetaType::Float
2892  const uint currentType = ((d.type == QMetaType::Float) ? QVariant::Double : d.type);
2893  if (uint(t) == uint(QMetaType::Float)) t = QVariant::Double;
2894 
2895  if (currentType == uint(t))
2896  return true;
2897 
2898  if (currentType > QVariant::LastCoreType || t > QVariant::LastCoreType) {
2899  switch (uint(t)) {
2900  case QVariant::Int:
2901  return currentType == QVariant::KeySequence
2902  || currentType == QMetaType::ULong
2903  || currentType == QMetaType::Long
2904  || currentType == QMetaType::UShort
2905  || currentType == QMetaType::UChar
2906  || currentType == QMetaType::Char
2907  || currentType == QMetaType::Short;
2908  case QVariant::Image:
2909  return currentType == QVariant::Pixmap || currentType == QVariant::Bitmap;
2910  case QVariant::Pixmap:
2911  return currentType == QVariant::Image || currentType == QVariant::Bitmap
2912  || currentType == QVariant::Brush;
2913  case QVariant::Bitmap:
2914  return currentType == QVariant::Pixmap || currentType == QVariant::Image;
2915  case QVariant::ByteArray:
2916  return currentType == QVariant::Color;
2917  case QVariant::String:
2918  return currentType == QVariant::KeySequence || currentType == QVariant::Font
2919  || currentType == QVariant::Color;
2920  case QVariant::KeySequence:
2921  return currentType == QVariant::String || currentType == QVariant::Int;
2922  case QVariant::Font:
2923  return currentType == QVariant::String;
2924  case QVariant::Color:
2925  return currentType == QVariant::String || currentType == QVariant::ByteArray
2926  || currentType == QVariant::Brush;
2927  case QVariant::Brush:
2928  return currentType == QVariant::Color || currentType == QVariant::Pixmap;
2929  case QMetaType::Long:
2930  case QMetaType::Char:
2931  case QMetaType::UChar:
2932  case QMetaType::ULong:
2933  case QMetaType::Short:
2934  case QMetaType::UShort:
2935  return qCanConvertMatrix[QVariant::Int] & (1 << currentType) || currentType == QVariant::Int;
2936  default:
2937  return false;
2938  }
2939  }
2940 
2941  if(t == String && currentType == StringList)
2942  return v_cast<QStringList>(&d)->count() == 1;
2943  else
2944  return qCanConvertMatrix[t] & (1 << currentType);
2945 }
const T * v_cast(const QVariant::Private *d, T *=0)
Definition: qvariant_p.h:78
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
unsigned int uint
Definition: qglobal.h:996
static const quint32 qCanConvertMatrix[QVariant::LastCoreType+1]
Definition: qvariant.cpp:2771
Private d
Definition: qvariant.h:417

◆ canConvert() [2/2]

template<typename T >
bool QVariant::canConvert ( ) const
inline

Returns true if the variant can be converted to the template type T, otherwise false.

Example:

QVariant v = 42;
v.canConvert<int>(); // returns true
v.canConvert<QString>(); // returns true
MyCustomStruct s;
v.setValue(s);
v.canConvert<int>(); // returns false
v.canConvert<MyCustomStruct>(); // returns true
See also
convert()

Definition at line 340 of file qvariant.h.

341  { return canConvert(Type(qMetaTypeId<T>())); }
bool canConvert() const
Returns true if the variant can be converted to the template type T, otherwise false.
Definition: qvariant.h:340
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95

◆ clear()

void QVariant::clear ( )

Convert this variant to type Invalid and free up any resources used.

Definition at line 1993 of file qvariant.cpp.

Referenced by QAbstractSpinBoxPrivate::clearCache(), convert(), load(), operator=(), QDBusAbstractInterfacePrivate::property(), and QDateTimeEditPrivate::validateAndInterpret().

1994 {
1995  if ((d.is_shared && !d.data.shared->ref.deref()) || (!d.is_shared && d.type < UserType && d.type > Char))
1996  handler->clear(&d);
1997  d.type = Invalid;
1998  d.is_null = true;
1999  d.is_shared = false;
2000 }
static const Handler * handler
Definition: qvariant.h:419
ushort Char
Private d
Definition: qvariant.h:417

◆ cmp()

bool QVariant::cmp ( const QVariant v) const
protected
Warning
This function is not part of the public interface.

Definition at line 3046 of file qvariant.cpp.

Referenced by isDetached().

3047 {
3048  QVariant v2 = v;
3049  if (d.type != v2.d.type) {
3050  if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) {
3051  if (qIsFloatingPoint(d.type) || qIsFloatingPoint(v.d.type))
3052  return qFuzzyCompare(toReal(), v.toReal());
3053  else
3054  return toLongLong() == v.toLongLong();
3055  }
3056  if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type)))
3057  return false;
3058  }
3059  return handler->compare(&d, &v2.d);
3060 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
static Q_DECL_CONSTEXPR bool qFuzzyCompare(double p1, double p2)
Definition: qglobal.h:2030
qlonglong toLongLong(bool *ok=0) const
Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or ULongLong ; otherwise returns 0.
Definition: qvariant.cpp:2659
static const Handler * handler
Definition: qvariant.h:419
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
static bool qIsFloatingPoint(uint tp)
Definition: qvariant.cpp:3039
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static bool qIsNumericType(uint tp)
Definition: qvariant.cpp:3033
bool convert(Type t)
Casts the variant to the requested type, t.
Definition: qvariant.cpp:2959
Private d
Definition: qvariant.h:417
qreal toReal(bool *ok=0) const
Returns the variant as a qreal if the variant has type() Double , QMetaType::Float ...
Definition: qvariant.cpp:2740

◆ constData()

const void * QVariant::constData ( ) const

◆ convert()

bool QVariant::convert ( Type  t)

Casts the variant to the requested type, t.

If the cast cannot be done, the variant is cleared. Returns true if the current type of the variant was successfully cast; otherwise returns false.

Warning
For historical reasons, converting a null QVariant results in a null value of the desired type (e.g., an empty string for QString) and a result of false.
See also
canConvert(), clear()

Definition at line 2959 of file qvariant.cpp.

Referenced by QScript::callQtMethod(), cmp(), QVariantAnimationPrivate::convertValues(), QDeclarativePropertyAnimationPrivate::convertVariant(), data(), QIBaseResult::gotoNext(), QScriptEnginePrivate::jscValueToVariant(), parseColorValue(), QCss::Parser::parseTerm(), QDeclarativeObjectMethodScriptClass::property(), QVariantToVARIANT(), QMimeDataPrivate::retrieveTypedData(), setFontSizeFromValue(), QScript::variantFromValue(), VARIANTToQVariant(), QDeclarativePropertyPrivate::write(), QMetaProperty::write(), and QDeclarativePropertyPrivate::writeEnumProperty().

2960 {
2961  if (d.type == uint(t))
2962  return true;
2963 
2964  QVariant oldValue = *this;
2965 
2966  clear();
2967  if (!oldValue.canConvert(t))
2968  return false;
2969 
2970  create(t, 0);
2971  if (oldValue.isNull())
2972  return false;
2973 
2974  bool isOk = true;
2975  if (!handler->convert(&oldValue.d, t, data(), &isOk))
2976  isOk = false;
2977  d.is_null = !isOk;
2978  return isOk;
2979 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
bool isNull() const
Returns true if this is a NULL variant, false otherwise.
Definition: qvariant.cpp:3102
void * data()
Definition: qvariant.cpp:3077
static const Handler * handler
Definition: qvariant.h:419
bool canConvert(Type t) const
Returns true if the variant&#39;s type can be cast to the requested type, t.
Definition: qvariant.cpp:2886
unsigned int uint
Definition: qglobal.h:996
void clear()
Convert this variant to type Invalid and free up any resources used.
Definition: qvariant.cpp:1993
Private d
Definition: qvariant.h:417

◆ create()

void QVariant::create ( int  type,
const void *  copy 
)
protected
Warning
This function is not part of the public interface.

Constructs a variant private of type type, and initializes with copy if copy is not 0.

Definition at line 1407 of file qvariant.cpp.

Referenced by convert(), data(), load(), and QVariant().

1408 {
1409  d.type = type;
1410  handler->construct(&d, copy);
1411 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901

◆ data() [1/2]

void * QVariant::data ( )

◆ data() [2/2]

const void * QVariant::data ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 326 of file qvariant.h.

326 { return constData(); }
const void * constData() const
Definition: qvariant.cpp:3065

◆ data_ptr()

DataPtr & QVariant::data_ptr ( )
inline
Warning
This function is not part of the public interface.

Definition at line 440 of file qvariant.h.

Referenced by qVariantSetValue().

440 { return d; }
Private d
Definition: qvariant.h:417

◆ detach()

void QVariant::detach ( )
Warning
This function is not part of the public interface.

Definition at line 1958 of file qvariant.cpp.

Referenced by data().

1959 {
1960  if (!d.is_shared || d.data.shared->ref == 1)
1961  return;
1962 
1963  Private dd;
1964  dd.type = d.type;
1965  handler->construct(&dd, constData());
1966  if (!d.data.shared->ref.deref())
1967  handler->clear(&d);
1968  d.data.shared = dd.data.shared;
1969 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417
const void * constData() const
Definition: qvariant.cpp:3065

◆ fromValue()

template<typename T >
static QVariant QVariant::fromValue ( const T &  value)
inlinestatic

Returns a QVariant containing a copy of value.

Behaves exactly like setValue() otherwise.

Example:

MyCustomStruct s;
Note
If you are working with custom types, you should use the Q_DECLARE_METATYPE() macro to register your custom type.
See also
setValue(), value()

Definition at line 336 of file qvariant.h.

Referenced by QDBusConnectionPrivate::activateCall(), QNetworkManagerInterface::activateConnection(), QDeclarativeListAccessor::at(), QXmlQuery::bindVariable(), QScript::ClassObjectDelegate::call(), QConnmanManagerInterface::connectService(), QScript::ClassObjectDelegate::construct(), QDeclarativeContext::contextProperty(), NamedNodeMap::create(), NodeList::create(), Node::create(), QNetworkAccessManager::createRequest(), QLocale::createSeparatedList(), QDeclarativeEnginePrivate::darker(), QNetworkManagerInterface::deactivateConnection(), QDeclarativeEngineDebugPrivate::decode(), QConnmanManagerInterface::disableTechnology(), QNetworkSessionPrivateImpl::do_open(), QConnmanManagerInterface::enableTechnology(), QBBInputContext::eventFilter(), QScriptDebuggerCommandExecutor::execute(), QDeclarativeEnginePrivate::formatDate(), QDeclarativeEnginePrivate::formatDateTime(), QDeclarativeEnginePrivate::formatTime(), QDeclarativeCustomParserNodePrivate::fromProperty(), QSQLiteResult::handle(), QSQLite2Result::handle(), QPSQLResult::handle(), QMYSQLResult::handle(), QOCIResult::handle(), QSQLiteDriver::handle(), QOCIDriver::handle(), QSQLite2Driver::handle(), QMYSQLDriver::handle(), QPSQLDriver::handle(), QScript::ClassObjectDelegate::hasInstance(), QDeclarativeEnginePrivate::hsla(), QHttpNetworkConnectionChannel::init(), QDeclarativeVisualDataModelPartsMetaObject::initialValue(), NestedListModel::insert(), QAccessibleAbstractSpinBox::invokeMethodEx(), QAccessibleWidgetEx::invokeMethodEx(), QAccessibleAbstractSlider::invokeMethodEx(), QAccessibleTextEdit::invokeMethodEx(), QAccessibleLineEdit::invokeMethodEx(), QOCIResult::lastInsertId(), QDeclarativeEnginePrivate::lighter(), Document::load(), QConnmanManagerInterface::lookupService(), messageToScriptValue(), QDeclarativeVisualDataModel::modelIndex(), operator<<(), QDeclarativeVisualDataModel::parentModelIndex(), parseCookieHeader(), parseHeaderValue(), QTipLabel::placeTip(), QDeclarativeEnginePrivate::point(), QVideoSurfaceFormat::property(), qDBusPropertyGet(), qDBusPropertyGetAll(), qmlsqldatabase_change_version(), qmlsqldatabase_executeSql(), qmlsqldatabase_open_sync(), qmlsqldatabase_transaction_shared(), QLocale::quoteString(), QDeclarativePropertyPrivate::readValueProperty(), QDeclarativeVMEMetaObject::readVarPropertyAsVariant(), QDeclarativeEnginePrivate::rect(), QConnmanManagerInterface::registerCounter(), QConnmanManagerInterface::requestScan(), QConnmanManagerInterface::requestSession(), QDeclarativeEnginePrivate::rgba(), QDeclarativeWorkerScriptEnginePrivate::scriptValueToVariant(), QDeclarativeEnginePrivate::scriptValueToVariant(), QOfonoSmsInterface::sendMessage(), QOfonoPrimaryDataContextInterface::setApn(), QScriptDebuggerCommand::setBreakpointData(), QDeclarativeContext::setContextProperty(), QDeclarativeListModelParser::setCustomData(), QDeclarativeVisualDataModel::setDelegate(), QDeclarativeListAccessor::setList(), ModelNode::setListValue(), ModelNode::setObjectValue(), QScriptDebuggerResponse::setResult(), QScriptDebuggerEvent::setScriptValue(), QScriptDebuggerCommand::setScriptValue(), QScriptDebuggerCommand::setSubordinateScriptValue(), QDeclarativeEnginePrivate::size(), QNetworkAccessBackend::start(), QDeclarativeEnginePrivate::tint(), QLocale::toCurrencyString(), QPatternist::AtomicValue::toQt(), QDeclarativeListScriptClass::toVariant(), QScriptEnginePrivate::toVariant(), QDBusDemarshaller::toVariantInternal(), QConnmanManagerInterface::unregisterCounter(), QDeclarativeBinding::update(), NestedListModel::valueForNode(), QDeclarativeStringConverters::variantFromString(), VARIANTToQVariant(), and QDeclarativeEnginePrivate::vector3d().

337  { return qVariantFromValue(value); }
QVariant qVariantFromValue(const T &value)
Returns a variant containing a copy of the given value with template type T.
Definition: qvariant.h:451
T value() const
Returns the stored value converted to the template type T.
Definition: qvariant.h:332

◆ isDetached()

bool QVariant::isDetached ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 537 of file qvariant.h.

Referenced by qVariantSetValue().

538 { return !d.is_shared || d.data.shared->ref == 1; }
Private d
Definition: qvariant.h:417

◆ isNull()

bool QVariant::isNull ( ) const

Returns true if this is a NULL variant, false otherwise.

Definition at line 3102 of file qvariant.cpp.

Referenced by QNetworkReplyImplPrivate::_q_copyReadyRead(), QLocale::amText(), QPatternist::VariableLoader::announceExternalVariable(), QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions(), QOCIResultPrivate::bindValues(), QAbstractSpinBoxPrivate::bound(), convert(), QPatternist::URILoader::createRequest(), QLocale::createSeparatedList(), QLocale::currencySymbol(), QLocale::dateFormat(), QLocale::dateTimeFormat(), QLocale::dayName(), QPatternist::VariableLoader::evaluateSequence(), QIBaseResult::exec(), QDB2Result::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QODBCResult::exec(), QSqlResult::exec(), QOCICols::execBatch(), QNetworkReplyImplPrivate::finished(), QLocale::firstDayOfWeek(), QUrlModel::flags(), QConnmanManagerInterface::getServices(), QConnmanManagerInterface::getTechnologies(), QStyledItemDelegate::initStyleOption(), QDB2Result::isNull(), QSqlCachedResult::isNull(), QODBCResult::isNull(), QTextDocument::loadResource(), QLocale::measurementSystem(), QLocale::monthName(), QLocale::nativeCountryName(), QLocale::nativeLanguageName(), operator<<(), QTextTableData::paddingProperty(), QItemDelegate::paint(), QLocale::pmText(), qCreateParamString(), qMakeFieldInfo(), qt_keyrelease_scanner(), QLocale::quoteString(), QXmlItem::QXmlItem(), QItemDelegate::rect(), QInternalMimeData::retrieveData(), QAbstractXmlNodeModel::sequencedTypedValue(), QNetworkHeadersPrivate::setCookedHeader(), QVideoSurfaceFormat::setProperty(), QSqlTableModelPrivate::setRecord(), ShaderEffectItem::setSource(), QLocale::standaloneDayName(), QLocale::standaloneMonthName(), QSimpleXmlNodeModel::stringValue(), QTextBlockFormat::tabPositions(), QLocale::timeFormat(), QLocale::toCurrencyString(), QTest::toString(), QLocale::toString(), QLocale::uiLanguages(), QLocalePrivate::updateSystemPrivate(), QMYSQLResult::virtual_hook(), and QLocale::weekdays().

3103 {
3104  return handler->isNull(&d);
3105 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ isValid()

bool QVariant::isValid ( ) const
inline

Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false.

Definition at line 485 of file qvariant.h.

Referenced by QStateMachinePrivate::applyProperties(), QDBusAbstractInterface::asyncCall(), QStyleSheetStyleSelector::attribute(), QDBusAbstractInterface::call(), QScript::callQtMethod(), QItemDelegate::check(), QTreeWidgetItem::childrenCheckState(), QDeclarativeContext::contextProperty(), QNetworkAccessManager::createRequest(), QSqlRelationalTableModel::data(), QProxyFontEngine::drawAsOutline(), QAxBase::dynamicCall(), QStyledItemDelegate::editorEvent(), QItemDelegate::editorEvent(), QScriptDebuggerCommandExecutor::execute(), QDeclarativeInclude::finished(), QDeclarativeXMLHttpRequest::finished(), QStandardItem::flags(), QNetworkReplyImplPrivate::getDownloadBuffer(), QApplicationPrivate::globalEventProcessor(), QSqlQueryModel::headerData(), QAbstractItemDelegate::helpEvent(), QColorDialogPrivate::init(), QNetworkReplyImplPrivate::initCacheSaveDevice(), QStateMachinePrivate::initializeAnimation(), QSideBarDelegate::initStyleOption(), QStyledItemDelegate::initStyleOption(), QDeclarativeItem::inputMethodQuery(), QComboBox::insertItem(), QAxBase::internalInvoke(), QAxServerBase::Invoke(), QNetworkManagerSettingsConnection::isAutoConnect(), QTreeModel::itemData(), QAbstractItemModel::itemData(), kdeColor(), load(), loadSingleEngine(), QDeclarativeAnimatedImage::movieRequestFinished(), QDeclarativeDataLoader::networkReplyFinished(), QDeclarativePixmapReader::networkRequestDone(), QAxEventSink::OnChanged(), QItemDelegate::paint(), QHeaderView::paintEvent(), QHeaderView::paintSection(), QNetworkAccessHttpBackend::postRequest(), QNetworkAccessManagerPrivate::prepareMultipart(), qDBusPropertyGet(), qt_mac_update_os_settings(), QDBusAbstractInterfaceBase::qt_metacall(), QAxBase::querySubObject(), readAllProperties(), QVariantAnimationPrivate::recalculateCurrentInterval(), QItemDelegate::rect(), QDeclarativeFontObject::replyFinished(), QDeclarativeXmlListModel::requestFinished(), QDeclarativeXMLHttpRequest::requestFromUrl(), QDeclarativeEngineDebugService::resetBinding(), QTextDocument::resource(), QMimeDataPrivate::retrieveTypedData(), save(), QAxServerBase::Save(), QDeclarativeBorderImage::sciRequestFinished(), QHeaderView::sectionSizeFromContents(), QHeaderView::sectionSizeHint(), QNetworkAccessCacheBackend::sendCacheContents(), QScriptDebuggerEvent::setAttribute(), QNetworkRequest::setAttribute(), QScriptDebuggerCommand::setAttribute(), QNetworkAccessBackend::setAttribute(), QNetworkReply::setAttribute(), QStandardItem::setData(), QTableModel::setData(), QTreeWidgetItem::setData(), QStyledItemDelegate::setEditorData(), QItemDelegate::setEditorData(), QDeclarativePropertyAnimation::setFrom(), QStandardItemPrivate::setItemData(), QDeclarativeListAccessor::setList(), QItemDelegate::setOptions(), QPrinter::setOutputFormat(), QStyleSheetStyle::setPalette(), QObject::setProperty(), QTextFormat::setProperty(), QNetworkSessionPrivateImpl::setSessionProperty(), QDeclarativePropertyAnimation::setTo(), QNetworkReplyImplPrivate::setup(), QVariantAnimationPrivate::setValueAt(), QStyledItemDelegate::sizeHint(), QItemDelegate::sizeHint(), QHttpSocketEngine::slotSocketConnected(), QScriptEngineDebugger::standardWindow(), QNetworkAccessBackend::start(), QMacStylePrivate::timerEvent(), QTest::toString(), QPatternist::AtomicValue::toXDM(), QDeclarativeTransitionManager::transition(), QStyleSheetStyle::unsetPalette(), QPropertyAnimation::updateState(), QHeaderView::viewportEvent(), QWizardHeader::vistaDisabled(), QWizardPrivate::vistaDisabled(), and QAbstractSocket::waitForConnected().

485 { return d.type != Invalid; }
Private d
Definition: qvariant.h:417

◆ load()

void QVariant::load ( QDataStream s)

Internal function for loading a variant from stream s.

Use the stream operators instead.

Warning
This function is not part of the public interface.

Definition at line 2093 of file qvariant.cpp.

Referenced by operator>>().

2094 {
2095  clear();
2096 
2097  quint32 u;
2098  s >> u;
2099  if (s.version() < QDataStream::Qt_4_0) {
2100  if (u >= MapFromThreeCount)
2101  return;
2102  u = map_from_three[u];
2103  }
2104  qint8 is_null = false;
2105  if (s.version() >= QDataStream::Qt_4_2)
2106  s >> is_null;
2107  if (u == QVariant::UserType) {
2108  QByteArray name;
2109  s >> name;
2110  u = QMetaType::type(name);
2111  if (!u) {
2113  return;
2114  }
2115  }
2116  create(static_cast<int>(u), 0);
2117  d.is_null = is_null;
2118 
2119  if (!isValid()) {
2120  // Since we wrote something, we should read something
2121  QString x;
2122  s >> x;
2123  d.is_null = true;
2124  return;
2125  }
2126 
2127  // const cast is safe since we operate on a newly constructed variant
2128  if (!QMetaType::load(s, d.type, const_cast<void *>(constData()))) {
2130  qWarning("QVariant::load: unable to load type %d.", d.type);
2131  }
2132 }
void create(int type, const void *copy)
Definition: qvariant.cpp:1407
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
quint16 u
void setStatus(Status status)
Sets the status of the data stream to the status given.
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const ushort map_from_three[MapFromThreeCount]
Definition: qvariant.cpp:2047
signed char qint8
Definition: qglobal.h:933
const char * name
Q_CORE_EXPORT void qWarning(const char *,...)
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
void clear()
Convert this variant to type Invalid and free up any resources used.
Definition: qvariant.cpp:1993
Private d
Definition: qvariant.h:417
const void * constData() const
Definition: qvariant.cpp:3065
unsigned int quint32
Definition: qglobal.h:938
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static bool load(QDataStream &stream, int type, void *data)
Reads the object of the specified type from the given stream into data.
Definition: qmetatype.cpp:845

◆ nameToType()

QVariant::Type QVariant::nameToType ( const char *  name)
static

Converts the string representation of the storage type given in name, to its enum representation.

If the string representation cannot be converted to any enum representation, the variant is set to Invalid.

Definition at line 2026 of file qvariant.cpp.

Referenced by MetaObjectGenerator::addProperty(), QDBusMetaObjectGenerator::findType(), QAxBase::internalInvoke(), QAxServerBase::Invoke(), qax_generateDocumentation(), qDBusNameToTypeId(), QAxServerBase::qt_metacall(), QVariantToVARIANT(), QMetaProperty::read(), toType(), VARIANTToQVariant(), and QMetaProperty::write().

2027 {
2028  if (!name || !*name)
2029  return Invalid;
2030  if (strcmp(name, "Q3CString") == 0)
2031  return ByteArray;
2032  if (strcmp(name, "Q_LLONG") == 0)
2033  return LongLong;
2034  if (strcmp(name, "Q_ULLONG") == 0)
2035  return ULongLong;
2036  if (strcmp(name, "QIconSet") == 0)
2037  return Icon;
2038  if (strcmp(name, "UserType") == 0)
2039  return UserType;
2040 
2041  int metaType = QMetaType::type(name);
2042  return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;
2043 }
const char * name
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
static int type(const char *typeName)
Returns a handle to the type called typeName, or 0 if there is no such type.
Definition: qmetatype.cpp:607

◆ operator!=()

bool QVariant::operator!= ( const QVariant v) const
inline

Compares this QVariant with v and returns true if they are not equal; otherwise returns false.

Warning
This function doesn't support custom types registered with qRegisterMetaType().

Definition at line 406 of file qvariant.h.

407  { return !cmp(v); }
bool cmp(const QVariant &other) const
Definition: qvariant.cpp:3046

◆ operator=()

QVariant & QVariant::operator= ( const QVariant other)

Assigns the value of the variant variant to this variant.

Definition at line 1921 of file qvariant.cpp.

Referenced by QDBusVariant::setVariant().

1922 {
1923  if (this == &variant)
1924  return *this;
1925 
1926  clear();
1927  if (variant.d.is_shared) {
1928  variant.d.data.shared->ref.ref();
1929  d = variant.d;
1930  } else if (variant.d.type > Char && variant.d.type < UserType) {
1931  d.type = variant.d.type;
1932  handler->construct(&d, variant.constData());
1933  d.is_null = variant.d.is_null;
1934  } else {
1935  d = variant.d;
1936  }
1937 
1938  return *this;
1939 }
static const Handler * handler
Definition: qvariant.h:419
ushort Char
void clear()
Convert this variant to type Invalid and free up any resources used.
Definition: qvariant.cpp:1993
Private d
Definition: qvariant.h:417
const char * variant

◆ operator==()

bool QVariant::operator== ( const QVariant v) const
inline

Compares this QVariant with v and returns true if they are equal; otherwise returns false.

In the case of custom types, their equalness operators are not called. Instead the values' addresses are compared.

Definition at line 404 of file qvariant.h.

405  { return cmp(v); }
bool cmp(const QVariant &other) const
Definition: qvariant.cpp:3046

◆ save()

void QVariant::save ( QDataStream s) const

Internal function for saving a variant to the stream s.

Use the stream operators instead.

Warning
This function is not part of the public interface.

Definition at line 2140 of file qvariant.cpp.

Referenced by operator<<().

2141 {
2142  quint32 tp = type();
2143  if (s.version() < QDataStream::Qt_4_0) {
2144  int i;
2145  for (i = MapFromThreeCount - 1; i >= 0; i--) {
2146  if (map_from_three[i] == tp) {
2147  tp = i;
2148  break;
2149  }
2150  }
2151  if (i == -1) {
2152  s << QVariant();
2153  return;
2154  }
2155  }
2156  s << tp;
2157  if (s.version() >= QDataStream::Qt_4_2)
2158  s << qint8(d.is_null);
2159  if (tp == QVariant::UserType) {
2160  s << QMetaType::typeName(userType());
2161  }
2162 
2163  if (!isValid()) {
2164  s << QString();
2165  return;
2166  }
2167 
2168  if (!QMetaType::save(s, d.type, constData())) {
2169  Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
2170  qWarning("QVariant::save: unable to save type %d.", d.type);
2171  }
2172 }
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const ushort map_from_three[MapFromThreeCount]
Definition: qvariant.cpp:2047
signed char qint8
Definition: qglobal.h:933
Q_CORE_EXPORT void qWarning(const char *,...)
QVariant()
Constructs an invalid variant.
Definition: qvariant.h:484
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
Private d
Definition: qvariant.h:417
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901
const void * constData() const
Definition: qvariant.cpp:3065
unsigned int quint32
Definition: qglobal.h:938
bool isValid() const
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false...
Definition: qvariant.h:485
static bool save(QDataStream &stream, int type, const void *data)
Writes the object pointed to by data with the ID type to the given stream.
Definition: qmetatype.cpp:646

◆ setValue()

template<typename T >
void QVariant::setValue ( const T &  value)
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:

v.setValue(5);
int i = v.toInt(); // i is now 5
QString s = v.toString() // s is now "5"
MyCustomStruct c;
v.setValue(c);
...
MyCustomStruct c2 = v.value<MyCustomStruct>();
See also
value(), fromValue(), canConvert()

Definition at line 527 of file qvariant.h.

Referenced by QAxBase::asVariant(), QScript::callQtMethod(), QDeclarativePropertyAnimationPrivate::convertVariant(), QAxBase::internalInvoke(), QTextBlockFormat::setTabPositions(), and VARIANTToQVariant().

528 { qVariantSetValue(*this, avalue); }
void qVariantSetValue(QVariant &variant, const T &value)
Sets the contents of the given variant to a copy of the value with the specified template type T...
Definition: qvariant.h:460

◆ swap()

void QVariant::swap ( QVariant other)
inline

Swaps variant other with this variant.

Since
4.8

This operation is very fast and never fails.

Definition at line 227 of file qvariant.h.

227 { qSwap(d, other.d); }
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
Private d
Definition: qvariant.h:417

◆ toBitArray()

QBitArray QVariant::toBitArray ( ) const

Returns the variant as a QBitArray if the variant has type() BitArray ; otherwise returns an empty bit array.

See also
canConvert(), convert()

Definition at line 2590 of file qvariant.cpp.

2591 {
2592  return qVariantToHelper<QBitArray>(d, BitArray, handler);
2593 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toBool()

bool QVariant::toBool ( ) const

Returns the variant as a bool if the variant has type() Bool.

Returns true if the variant has type() 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.

See also
canConvert(), convert()

Definition at line 2691 of file qvariant.cpp.

Referenced by allowsMessages(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QTextFormat::boolProperty(), QNetworkManagerInterfaceDeviceWired::carrier(), QPaintBuffer::commandDescription(), copyArgument(), QNetworkReplyImplPrivate::createCache(), QNetworkManagerConnectionActive::defaultRoute(), QIcdEngine::doRequestUpdate(), QTextLine::draw(), QProxyFontEngine::drawAsOutline(), QWindowsVistaStyle::drawControl(), QSqlDriver::formatValue(), QPSQLDriver::formatValue(), getNetworkAttrs(), QScript::ClassObjectDelegate::hasInstance(), QNetworkManagerSettingsConnection::isAutoConnect(), QmlJSDebugger::isEditorItem(), QGraphicsWidget::itemChange(), loadSingleEngine(), macValue(), QPSPrintEnginePrivate::QPSPrintEnginePrivate(), qt_mac_update_os_settings(), QVariantToVoidStar(), QIBaseResult::record(), QPSQLDriver::record(), QTextEditPrivate::relayoutDocument(), QTextEdit::resizeEvent(), QStyleSheetStyle::setGeometry(), setPenAndDrawBackground(), QMacPrintEngine::setProperty(), QWin32PrintEngine::setProperty(), QtopiaPrintEngine::setProperty(), QPdfBaseEngine::setProperty(), QGraphicsItem::setSelected(), QNetworkSessionPrivateImpl::setSessionProperty(), QNetworkReplyImplPrivate::setup(), QGraphicsItemPrivate::setVisibleHelper(), streamDebug(), QImageReader::supportsAnimation(), QPatternist::AtomicValue::toXDM(), QDeclarativeStateGroupPrivate::updateAutoState(), ShaderEffectItem::updateEffectState(), variantHash(), QScript::variantProtoFuncValueOf(), QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(), variantToString(), Maemo::IAPConfPrivate::variantToValue(), QWizardHeader::vistaDisabled(), QWizardPrivate::vistaDisabled(), QNetworkManagerInterface::wirelessEnabled(), QNetworkManagerInterface::wirelessHardwareEnabled(), and QApplicationPrivate::x11_apply_settings().

2692 {
2693  if (d.type == Bool)
2694  return d.data.b;
2695 
2696  bool res = false;
2697  handler->convert(&d, Bool, &res, 0);
2698 
2699  return res;
2700 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toByteArray()

QByteArray QVariant::toByteArray ( ) const

Returns the variant as a QByteArray if the variant has type() ByteArray or String (converted using QString::fromAscii()); otherwise returns an empty byte array.

See also
canConvert(), convert()

Definition at line 2383 of file qvariant.cpp.

Referenced by QIcdEngine::addConfiguration(), QFontDatabasePrivate::addQPF2File(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QTextHtmlParserNode::applyBackgroundImage(), QIcdEngine::asyncUpdateConfigurationsSlot(), QMacPasteboardMimeAny::convertFromMime(), QMacPasteboardMimeHTMLText::convertFromMime(), QMacPasteboardMimeVCard::convertFromMime(), copyArgument(), QMimeData::data(), QIcdEngine::doRequestUpdate(), QDeclarativeXMLHttpRequest::downloadProgress(), QDeclarativeXMLHttpRequest::error(), QIBaseResult::exec(), QDB2Result::exec(), QODBCResult::exec(), QOCICols::execBatch(), QDeclarativeXMLHttpRequest::finished(), QDB2Driver::formatValue(), QSqlDriver::formatValue(), QTDSDriver::formatValue(), QMYSQLDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), headerValue(), QTextHtmlParser::importStyleSheet(), QFileDialogPrivate::init(), QTextDocument::loadResource(), macValue(), QVariantToVoidStar(), QOCICols::readPiecewise(), QPlatformFontDatabase::registerQPF2Font(), QInternalMimeData::retrieveData(), QMimeDataPrivate::retrieveTypedData(), QPpmHandler::setOption(), QTextBrowserPrivate::setSource(), QPageSetupWidget::setupPrinter(), QHttpSocketEngine::slotSocketConnected(), QScriptEngineDebugger::standardWindow(), streamDebug(), toUrl(), QPatternist::AtomicValue::toXDM(), variantToString(), QSettingsPrivate::variantToString(), Maemo::IAPConfPrivate::variantToValue(), QMYSQLResult::virtual_hook(), QDeclarativePropertyPrivate::write(), QMetaProperty::write(), and QDeclarativePropertyPrivate::writeEnumProperty().

2384 {
2385  return qVariantToHelper<QByteArray>(d, ByteArray, handler);
2386 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toChar()

QChar QVariant::toChar ( ) const

Returns the variant as a QChar if the variant has type() Char , Int , or UInt ; otherwise returns an invalid QChar.

See also
canConvert(), convert()

Definition at line 2579 of file qvariant.cpp.

Referenced by Maemo::appendVariantToDBusMessage(), QSortFilterProxyModel::lessThan(), QStandardItem::operator<(), and streamDebug().

2580 {
2581  return qVariantToHelper<QChar>(d, Char, handler);
2582 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toDate()

QDate QVariant::toDate ( ) const

◆ toDateTime()

QDateTime QVariant::toDateTime ( ) const

Returns the variant as a QDateTime if the variant has type() 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 cannot be parsed as a Qt::ISODate format date/time.

See also
canConvert(), convert()

Definition at line 2349 of file qvariant.cpp.

Referenced by QOCIResultPrivate::bindValue(), QStyledItemDelegate::displayText(), QDateTimeEditPrivate::emitSignals(), QIBaseResult::exec(), QDB2Result::exec(), QODBCResult::exec(), QOCICols::execBatch(), QDB2Driver::formatValue(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QOCIDriver::formatValue(), QTDSDriver::formatValue(), QODBCDriver::formatValue(), QPSQLDriver::formatValue(), QDateTimeEditPrivate::getMaximum(), QDateTimeEditPrivate::getMinimum(), headerValue(), QSortFilterProxyModel::lessThan(), macValue(), operator*(), operator+(), operator-(), operator/(), QStandardItem::operator<(), QSystemLocale::query(), QVariantToVoidStar(), QDateTimeEditPrivate::stepBy(), streamDebug(), QDateTimeEditPrivate::textFromValue(), QPatternist::AtomicValue::toXDM(), QDateTimeEditPrivate::updateTimeSpec(), QDateTimeEditPrivate::validateAndInterpret(), QItemDelegatePrivate::valueToText(), QAbstractSpinBoxPrivate::variantCompare(), and QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue().

2350 {
2351  return qVariantToHelper<QDateTime>(d, DateTime, handler);
2352 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toDouble()

double QVariant::toDouble ( bool *  ok = 0) const

◆ toEasingCurve()

QEasingCurve QVariant::toEasingCurve ( ) const

Returns the variant as a QEasingCurve if the variant has type() EasingCurve ; otherwise returns a default easing curve.

Since
4.7
See also
canConvert(), convert()

Definition at line 2366 of file qvariant.cpp.

Referenced by streamDebug().

2367 {
2368  return qVariantToHelper<QEasingCurve>(d, EasingCurve, handler);
2369 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toFloat()

float QVariant::toFloat ( bool *  ok = 0) const

Returns the variant as a float if the variant has type() Double , QMetaType::Float , Bool , ByteArray , Int , LongLong , String , UInt , or ULongLong ; otherwise returns 0.0.

Since
4.6

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.

See also
canConvert(), convert()

Definition at line 2725 of file qvariant.cpp.

Referenced by QSortFilterProxyModel::lessThan(), QStandardItem::operator<(), QPngHandler::setOption(), streamDebug(), QPatternist::AtomicValue::toXDM(), QItemDelegatePrivate::valueToText(), and variantHash().

2726 {
2727  return qNumVariantToHelper<float>(d, handler, ok, d.data.f);
2728 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toHash()

QVariantHash QVariant::toHash ( ) const

Returns the variant as a QHash<QString, QVariant> if the variant has type() Hash ; otherwise returns an empty map.

See also
canConvert(), convert()

Definition at line 2292 of file qvariant.cpp.

Referenced by streamDebug().

2293 {
2294  return qVariantToHelper<QVariantHash>(d, Hash, handler);
2295 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toInt()

int QVariant::toInt ( bool *  ok = 0) const

Returns the variant as an int if the variant has type() Int , Bool , ByteArray , Char , Double , LongLong , String , UInt , or 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 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(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also
canConvert(), convert()

Definition at line 2625 of file qvariant.cpp.

Referenced by QFileDialogPrivate::_q_deleteCurrent(), QCalendarWidgetPrivate::_q_monthChanged(), QPageSetupWidget::_q_paperSizeChanged(), QPrintDialogPrivate::_q_printRangeSelected(), QFontDatabasePrivate::addQPF2File(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QProxyFontEngine::ascent(), QIcdEngine::asyncUpdateConfigurationsSlot(), QNetworkAccessManagerPrivate::authenticationRequired(), QProxyFontEngine::averageCharWidth(), QSettings::beginReadArray(), QCss::Declaration::brushValues(), QTreeWidgetItem::childrenCheckState(), QCss::Declaration::colorValues(), QmlJSDebugger::LiveSelectionTool::contextMenuElementHovered(), QmlJSDebugger::LiveSelectionTool::contextMenuElementSelected(), copyArgument(), QDeclarativeListAccessor::count(), QNetworkReplyImplPrivate::createCache(), QNetworkAccessManager::createRequest(), QMYSQLResult::data(), QDeclarativeEngineDebugPrivate::decode(), QProxyFontEngine::descent(), QBBInputContext::dispatchRequestSoftwareInputPanel(), QDeclarativeXmlQueryEngine::doQueryJob(), QDeclarativeXMLHttpRequest::downloadProgress(), QWindowsVistaStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QWindowsVistaStyle::drawPrimitive(), QStyledItemDelegate::editorEvent(), QItemDelegate::editorEvent(), QDeclarativeXMLHttpRequest::error(), QIBaseResult::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QOCICols::execBatch(), QScriptDebuggerCommandExecutor::execute(), QScriptDebuggerAgent::extension(), QDeclarativeXMLHttpRequest::finished(), QStandardItem::flags(), QHeaderViewPrivate::flipSortIndicator(), QNetworkSessionManagerPrivate::forceSessionClose(), QProxyFontEngine::glyphCount(), QBBInputContext::hasSelectedText(), QImageReader::imageFormat(), QDeclarativeVisualDataModel::indexOf(), QMacPrintEnginePrivate::initialize(), QStyledItemDelegate::initStyleOption(), QTextFormat::intProperty(), QAccessibleTextEdit::invokeMethodEx(), QAccessibleLineEdit::invokeMethodEx(), QKde::kdeToolBarIconSize(), QProxyFontEngine::leading(), QSortFilterProxyModel::lessThan(), QProxyFontEngine::lineThickness(), QNetworkAccessHttpBackend::loadFromCacheIfAllowed(), macFormatCurrency(), macValue(), QProxyFontEngine::maxCharWidth(), QLocale::measurementSystem(), QNetworkReplyImplPrivate::metaDataChanged(), QProxyFontEngine::minLeftBearing(), QProxyFontEngine::minRightBearing(), QTextFormat::objectIndex(), QBBInputContext::onGetCursorPosition(), QBBInputContext::onGetTextAfterCursor(), QBBInputContext::onGetTextBeforeCursor(), QDeclarativeWorkerScriptEnginePrivate::onMessage(), QBBInputContext::onSetComposingRegion(), operator*(), operator+(), operator-(), operator/(), QStandardItem::operator<(), QItemDelegate::paint(), QHeaderView::paintSection(), parseColorValue(), parseCSStoXMLAttrs(), parseShorthandBackgroundProperty(), parseStyleValue(), QIBaseDriver::primaryIndex(), QSQLite2Driver::primaryIndex(), QPSQLDriver::primaryIndex(), qExtractSecurityPolicyFromString(), QFontEngineQPA::QFontEngineQPA(), QFontEngineQPF::QFontEngineQPF(), qGetTableInfo(), qMakeFieldInfo(), QApplicationPrivate::qt_mac_apply_settings(), qt_mac_update_os_settings(), QSystemLocale::query(), QVariantToVARIANT(), QVariantToVoidStar(), QIBaseResult::record(), QIBaseDriver::record(), QOCIDriver::record(), QTDSDriver::record(), QPSQLDriver::record(), QTextControlPrivate::rectForPosition(), QPlatformFontDatabase::registerQPF2Font(), QNetworkAccessHttpBackend::sendCacheContents(), QDeclarativeWorkerScriptEnginePrivate::sendMessage(), QWinSettingsPrivate::set(), QAccessibleAbstractSlider::setCurrentValue(), QScriptBreakpointsModel::setData(), setFontSizeFromValue(), setFontStyleFromValue(), setFontVariantFromValue(), setFontWeightFromValue(), QTextHtmlParserNode::setListStyle(), QTiffHandler::setOption(), QJpegHandler::setOption(), QPngHandler::setOption(), QItemDelegate::setOptions(), QDeclarativeValueTypeScriptClass::setProperty(), QMacPrintEngine::setProperty(), QWin32PrintEngine::setProperty(), QtopiaPrintEngine::setProperty(), QPdfBaseEngine::setProperty(), QAbstractSocket::setSocketOption(), setTextDecorationFromValues(), setTextTransformFromValue(), QPageSetupWidget::setupPrinter(), QAccessibleItemRow::state(), QAccessibleTable2Cell::state(), streamDebug(), QStyleSheetStyle::styleHint(), QPrinter::supportedPaperSources(), QPrinter::supportedResolutions(), QSpinBoxPrivate::textFromValue(), QMacStylePrivate::timerEvent(), QSystemLocalePrivate::toCurrencyString(), QProxyFontEngine::underlinePosition(), QTabBarPrivate::Tab::TabBarAnimation::updateCurrentValue(), ShaderEffectItem::updateEffectState(), QLocalePrivate::updateSystemPrivate(), QAbstractSpinBoxPrivate::variantCompare(), variantHash(), QScript::variantProtoFuncValueOf(), Maemo::IAPConfPrivate::variantToValue(), QApplicationPrivate::x11_apply_settings(), and QProxyFontEngine::xHeight().

2626 {
2627  return qNumVariantToHelper<int>(d, handler, ok, d.data.i);
2628 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toLine()

QLine QVariant::toLine ( ) const

Returns the variant as a QLine if the variant has type() Line ; otherwise returns an invalid QLine.

See also
canConvert(), convert()

Definition at line 2494 of file qvariant.cpp.

Referenced by streamDebug().

2495 {
2496  return qVariantToHelper<QLine>(d, Line, handler);
2497 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toLineF()

QLineF QVariant::toLineF ( ) const

Returns the variant as a QLineF if the variant has type() LineF ; otherwise returns an invalid QLineF.

See also
canConvert(), convert()

Definition at line 2478 of file qvariant.cpp.

Referenced by streamDebug().

2479 {
2480  return qVariantToHelper<QLineF>(d, LineF, handler);
2481 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toList()

QVariantList QVariant::toList ( ) const

Returns the variant as a QVariantList if the variant has type() List or StringList ; otherwise returns an empty list.

See also
canConvert(), convert()

Definition at line 2751 of file qvariant.cpp.

Referenced by Maemo::IcdPrivate::addrinfo(), Maemo::appendVariantToDBusMessage(), QMacPasteboardMimeFileUri::convertFromMime(), QMacPasteboardMimeUrl::convertFromMime(), createArrayBuffer(), QPatternist::VariableLoader::evaluateSequence(), QIBaseResult::exec(), QSqlResult::execBatch(), QOCICols::execBatch(), QScriptDebuggerAgent::extension(), Maemo::get_addrinfo_all_result(), QTextFormat::lengthVectorProperty(), macValue(), QMacPrintEngine::metric(), QMacPrintEngine::property(), QVariantToVARIANT(), QVariantToVoidStar(), QMimeDataPrivate::retrieveTypedData(), Maemo::IcdPrivate::scan(), QWinSettingsPrivate::set(), QMacPrintEngine::setProperty(), QWin32PrintEngine::setProperty(), QPdfBaseEngine::setProperty(), QStyleSheetStyle::sizeFromContents(), Maemo::IcdPrivate::state(), Maemo::IcdPrivate::statistics(), streamDebug(), QStyleSheetStyle::subControlRect(), QPrinter::supportedPaperSources(), QStyleSheetStyle::titleBarLayout(), QMimeData::urls(), QDeclarativeEngineDebugService::valueContents(), VARIANTToQVariant(), Maemo::variantToSignature(), variantToString(), Maemo::IAPConfPrivate::variantToValue(), and QConfFileSettingsPrivate::writeIniFile().

2752 {
2753  return qVariantToHelper<QVariantList>(d, List, handler);
2754 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toLocale()

QLocale QVariant::toLocale ( ) const

Returns the variant as a QLocale if the variant has type() Locale ; otherwise returns an invalid QLocale.

See also
canConvert(), convert()

Definition at line 2545 of file qvariant.cpp.

2546 {
2547  return qVariantToHelper<QLocale>(d, Locale, handler);
2548 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toLongLong()

qlonglong QVariant::toLongLong ( bool *  ok = 0) const

Returns the variant as a long long int if the variant has type() LongLong , Bool , ByteArray , Char , Double , Int , String , UInt , or 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.

See also
canConvert(), convert()

Definition at line 2659 of file qvariant.cpp.

Referenced by QNetworkReplyImplPrivate::_q_copyReadyRead(), QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QOCIResultPrivate::bindValue(), cmp(), copyArgument(), QMYSQLResult::data(), QStyledItemDelegate::displayText(), QIBaseResult::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QOCICols::execBatch(), QScriptDebuggerAgent::extension(), QNetworkReplyImplPrivate::finished(), QNetworkReplyImplPrivate::getDownloadBuffer(), QSortFilterProxyModel::lessThan(), macFormatCurrency(), macValue(), QStandardItem::operator<(), QNetworkAccessHttpBackend::postRequest(), QVariantToVARIANT(), QVariantToVoidStar(), QWinSettingsPrivate::set(), streamDebug(), QSystemLocalePrivate::toCurrencyString(), QPatternist::AtomicValue::toXDM(), QItemDelegatePrivate::valueToText(), QAbstractItemModelPrivate::variantLessThan(), and variantToString().

2660 {
2661  return qNumVariantToHelper<qlonglong>(d, handler, ok, d.data.ll);
2662 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toMap()

QVariantMap QVariant::toMap ( ) const

Returns the variant as a QMap<QString, QVariant> if the variant has type() Map ; otherwise returns an empty map.

See also
canConvert(), convert()

Definition at line 2281 of file qvariant.cpp.

Referenced by macValue(), streamDebug(), and QDeclarativeEngineDebugService::valueContents().

2282 {
2283  return qVariantToHelper<QVariantMap>(d, Map, handler);
2284 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toPoint()

QPoint QVariant::toPoint ( ) const

◆ toPointF()

QPointF QVariant::toPointF ( ) const

◆ toReal()

qreal QVariant::toReal ( bool *  ok = 0) const

◆ toRect()

QRect QVariant::toRect ( ) const

◆ toRectF()

QRectF QVariant::toRectF ( ) const

◆ toRegExp()

QRegExp QVariant::toRegExp ( ) const

Returns the variant as a QRegExp if the variant has type() RegExp ; otherwise returns an empty QRegExp.

Since
4.1
See also
canConvert(), convert()

Definition at line 2562 of file qvariant.cpp.

Referenced by QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue().

2563 {
2564  return qVariantToHelper<QRegExp>(d, RegExp, handler);
2565 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toSize()

QSize QVariant::toSize ( ) const

Returns the variant as a QSize if the variant has type() Size ; otherwise returns an invalid QSize.

See also
canConvert(), convert()

Definition at line 2432 of file qvariant.cpp.

Referenced by QGraphicsScenePrivate::drawItemHelper(), QStyleSheetStyle::pixelMetric(), QVariantToVoidStar(), QGraphicsSvgItem::setMaximumCacheSize(), QJpegHandler::setOption(), QSvgIOHandler::setOption(), QImageReader::size(), and streamDebug().

2433 {
2434  return qVariantToHelper<QSize>(d, Size, handler);
2435 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toSizeF()

QSizeF QVariant::toSizeF ( ) const

Returns the variant as a QSizeF if the variant has type() SizeF ; otherwise returns an invalid QSizeF.

See also
canConvert(), convert()

Definition at line 2447 of file qvariant.cpp.

Referenced by QMacPrintEngine::setProperty(), QWin32PrintEngine::setProperty(), QPdfBaseEngine::setProperty(), streamDebug(), and ShaderEffectItem::updateEffectState().

2448 {
2449  return qVariantToHelper<QSizeF>(d, SizeF, handler);
2450 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toString()

QString QVariant::toString ( ) const

Returns the variant as a QString if the variant has type() String , Bool , ByteArray , Char , Date , DateTime , Double , Int , LongLong , StringList , Time , UInt , or ULongLong ; otherwise returns an empty string.

See also
canConvert(), convert()

Definition at line 2270 of file qvariant.cpp.

Referenced by QFileDialogPrivate::_q_currentChanged(), QInputDialogPrivate::_q_currentRowChanged(), QFileDialogPrivate::_q_deleteCurrent(), QFileDialogPrivate::_q_enterDirectory(), QFileDialogPrivate::_q_goToDirectory(), QFileDialogPrivate::_q_navigateToParent(), QFileDialogPrivate::_q_selectionChanged(), QIcdEngine::addConfiguration(), QFontDatabasePrivate::addQPF2File(), QLocale::amText(), QTextCharFormat::anchorName(), QTextCharFormat::anchorNames(), QPSQLDriverPrivate::appendTables(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QIcdEngine::asyncUpdateConfigurationsSlot(), QStyleSheetStyleSelector::attribute(), QOCIResultPrivate::bindValue(), QCss::Declaration::borderImageValue(), QUnsortedModelEngine::buildIndices(), QMultiInputContext::changeSlave(), QAbstractItemViewPrivate::checkMouseMove(), QAccessibleTable2::columnDescription(), QAccessibleItemView::columnDescription(), QNetworkManagerEngine::connectToId(), convert(), QMacPasteboardMimeAny::convertFromMime(), QMacPasteboardMimePlainText::convertFromMime(), QMacPasteboardMimeUnicodeText::convertFromMime(), QMacPasteboardMimeVCard::convertFromMime(), QDeclarativePropertyAnimationPrivate::convertVariant(), copyArgument(), QLocale::createSeparatedList(), QLocale::currencySymbol(), QDeclarativeEnginePrivate::darker(), QSqlRelationalTableModel::data(), QDeclarativeFolderListModel::data(), QLocale::dateFormat(), QLocale::dateTimeFormat(), QLocale::dayName(), QStyledItemDelegate::displayText(), QIcdEngine::doRequestUpdate(), ModelNode::dump(), QTextHtmlExporter::emitBackgroundAttribute(), QIBaseResult::exec(), QDB2Result::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QODBCResult::exec(), QOCICols::execBatch(), QScript::QtPropertyFunction::execute(), QCss::ValueExtractor::extractBackground(), QFileSystemModel::fileName(), QSortedModelEngine::filter(), QCompletionEngine::filterHistory(), QDBusConnectionPrivate::findMetaObject(), fontNameSubstitute(), QSqlDriver::formatValue(), QNetworkManagerSettingsConnection::getId(), QNetworkManagerSettingsConnection::getMacAddress(), QDBusConnectionPrivate::getNameOwnerNoCache(), getNetworkAttrs(), QNetworkManagerSettingsConnection::getSsid(), QComboMenuDelegate::getStyleOption(), QImageReaderPrivate::getText(), QNetworkManagerSettingsConnection::getType(), QNetworkManagerSettingsConnection::getUuid(), QApplicationPrivate::globalEventProcessor(), QScriptToolTipJob::handleResponse(), QDBusConnectionPrivate::handleSignal(), QAbstractItemDelegate::helpEvent(), QMimeData::html(), QNetworkManagerInterfaceAccessPoint::hwAddress(), QNetworkManagerInterfaceDeviceWired::hwAddress(), QNetworkManagerInterfaceDeviceWireless::hwAddress(), QCss::Declaration::iconValue(), QTextHtmlParser::importStyleSheet(), intValueHelper(), Maemo::ProxyConfPrivate::isHostExcluded(), QComboBoxDelegate::isSeparator(), QComboBoxPrivate::itemText(), QKde::kdeStyle(), QKde::kdeToolButtonStyle(), QAbstractItemView::keyPressEvent(), QCss::ValueExtractor::lengthValue(), QSortFilterProxyModel::lessThan(), QDeclarativeEnginePrivate::lighter(), QLibraryInfo::location(), QAbstractItemModel::match(), QLocale::monthName(), QLocale::nativeCountryName(), QLocale::nativeLanguageName(), QNetworkManagerInterfaceDevice::networkInterface(), QAxSelect::on_ActiveXList_clicked(), QAxSelect::on_ActiveXList_doubleClicked(), QBBInputContext::onGetSelectedText(), QBBInputContext::onGetTextAfterCursor(), QBBInputContext::onGetTextBeforeCursor(), QBBInputContext::onSetComposingRegion(), QStandardItem::operator<(), operator<<(), QFontFamilyDelegate::paint(), QScriptDebuggerLocalsItemDelegate::paint(), QNetworkManagerEngine::parseConnection(), parseShorthandBackgroundProperty(), QFSCompleter::pathFromIndex(), QCompleter::pathFromIndex(), QLocale::pmText(), QRelation::populateDictionary(), QIBaseDriver::primaryIndex(), QOCIDriver::primaryIndex(), QSQLite2Driver::primaryIndex(), QTDSDriver::primaryIndex(), QMYSQLDriver::primaryIndex(), QPSQLDriver::primaryIndex(), qDBusPropertyGet(), qDBusPropertyGetAll(), qDBusPropertySet(), qExtractSecurityPolicyFromString(), qGetTableInfo(), qmlsqldatabase_executeSql(), qmlsqldatabase_item(), qmlsqldatabase_open_sync(), QMultiInputContext::QMultiInputContext(), QApplicationPrivate::qt_mac_apply_settings(), QFileDialogPrivate::qt_mac_filedialog_event_proc(), QSystemLocale::query(), QLocale::quoteString(), QVariantToVARIANT(), QVariantToVoidStar(), MetaObjectGenerator::readClassInfo(), MetaObjectGenerator::readEventInfo(), MetaObjectGenerator::readInterfaceInfo(), QOCICols::readPiecewise(), QCss::Declaration::realValue(), QIBaseDriver::record(), QOCIDriver::record(), QTDSDriver::record(), QPSQLDriver::record(), QPlatformFontDatabase::registerQPF2Font(), QDeclarativeXMLHttpRequest::requestFromUrl(), QFileDialogPrivate::retranslateStrings(), QMimeDataPrivate::retrieveTypedData(), QAccessibleTable2::rowDescription(), QAccessibleItemView::rowDescription(), Maemo::IcdPrivate::scan(), QFileDialog::selectedFiles(), QFileDialog::selectFile(), QNetworkManagerConnectionActive::serviceName(), QConnmanEngine::servicePropertyChangedContext(), QDeclarativeEngineDebugService::setBinding(), QAxBase::setControl(), QStringListModel::setData(), QScriptDebuggerLocalsModel::setData(), QDirModel::setData(), QSqlRelationalTableModel::setData(), QUrlModel::setData(), QScriptBreakpointsModel::setData(), QFileSystemModel::setData(), setFontFamilyFromValues(), setFontSizeFromValue(), QFileDialogComboBox::setHistory(), QXpmHandler::setOption(), QXbmHandler::setOption(), QPngHandler::setOption(), QMacPrintEngine::setProperty(), QWin32PrintEngine::setProperty(), QtopiaPrintEngine::setProperty(), QPdfBaseEngine::setProperty(), QTextBrowserPrivate::setSource(), QGraphicsItem::setToolTip(), QUrlModel::setUrl(), QFileDialogComboBox::showPopup(), QFontFamilyDelegate::sizeHint(), QNetworkManagerInterfaceAccessPoint::ssid(), QLocale::standaloneDayName(), QLocale::standaloneMonthName(), QNetworkSessionPrivateImpl::stateChange(), streamDebug(), QTextFormat::stringProperty(), QDeclarativeVisualDataModel::stringValue(), QNetworkSessionPrivateImpl::syncStateWithInterface(), QGuiPlatformPlugin::systemIconThemeName(), QIBaseDriver::tables(), QSQLiteDriver::tables(), QOCIDriver::tables(), QSQLite2Driver::tables(), QTDSDriver::tables(), QMYSQLDriver::tables(), QPSQLDriver::tables(), QConnmanEngine::technologyPropertyChangedContext(), QMimeData::text(), QAccessibleHeader::text(), QAccessibleItemRow::text(), QAccessibleTable2Cell::text(), QAccessibleTable2HeaderCell::text(), QAccessibleItemRow::text_helper(), QLocale::timeFormat(), QDeclarativeEnginePrivate::tint(), QLocale::toCurrencyString(), QGraphicsItem::toolTip(), QLocale::toString(), toUrl(), QPatternist::AtomicValue::toXDM(), QNetworkManagerInterfaceDevice::udi(), QItemDelegate::updateEditorGeometry(), QLocalePrivate::updateSystemPrivate(), QItemDelegatePrivate::valueToText(), variantHash(), QAbstractItemModelPrivate::variantLessThan(), QScript::variantProtoFuncToString(), QScript::variantProtoFuncValueOf(), VARIANTToQVariant(), QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(), variantToString(), QSettingsPrivate::variantToString(), Maemo::IAPConfPrivate::variantToValue(), QHeaderView::viewportEvent(), QMYSQLResult::virtual_hook(), QDeclarativePropertyPrivate::write(), and QApplicationPrivate::x11_apply_settings().

2271 {
2272  return qVariantToHelper<QString>(d, String, handler);
2273 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toStringList()

QStringList QVariant::toStringList ( ) const

◆ toTime()

QTime QVariant::toTime ( ) const

◆ toUInt()

uint QVariant::toUInt ( bool *  ok = 0) const

Returns the variant as an unsigned int if the variant has type() UInt , Bool , ByteArray , Char , Double , Int , LongLong , String , or 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 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(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also
canConvert(), convert()

Definition at line 2644 of file qvariant.cpp.

Referenced by Maemo::IcdPrivate::addrinfo(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QIcdEngine::asyncUpdateConfigurationsSlot(), QNetworkManagerInterfaceDeviceWireless::bitrate(), QLocalSocket::connectToServer(), copyArgument(), QNetworkManagerInterfaceDevice::deviceType(), QOCICols::execBatch(), QLocale::firstDayOfWeek(), QNetworkManagerInterfaceAccessPoint::flags(), QNetworkManagerInterfaceAccessPoint::frequency(), QNetworkManagerSettingsConnection::getTimestamp(), QColorDialogPrivate::init(), QNetworkManagerInterfaceDevice::ip4Address(), QSortFilterProxyModel::lessThan(), QNetworkManagerInterfaceAccessPoint::maxBitrate(), QNetworkManagerInterfaceAccessPoint::mode(), QNetworkManagerInterfaceDeviceWireless::mode(), QStandardItem::operator<(), QPainterReplayer::process(), QFontEngineQPF::QFontEngineQPF(), QVariantToVARIANT(), QVariantToVoidStar(), QDBusConnectionInterface::registerService(), QNetworkManagerInterfaceAccessPoint::rsnFlags(), QNetworkManagerInterfaceDeviceWired::speed(), Maemo::IcdPrivate::state(), QNetworkManagerInterface::state(), QNetworkManagerInterfaceDevice::state(), QNetworkManagerConnectionActive::state(), Maemo::IcdPrivate::statistics(), streamDebug(), QNetworkManagerInterfaceAccessPoint::strength(), QSystemLocalePrivate::toCurrencyString(), QDBusConnectionInterface::unregisterService(), QScript::variantProtoFuncValueOf(), QNetworkManagerInterfaceDeviceWireless::wirelessCapabilities(), and QNetworkManagerInterfaceAccessPoint::wpaFlags().

2645 {
2646  return qNumVariantToHelper<uint>(d, handler, ok, d.data.u);
2647 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toULongLong()

qulonglong QVariant::toULongLong ( bool *  ok = 0) const

Returns the variant as as an unsigned long long int if the variant has type() ULongLong , Bool , ByteArray , Char , Double , Int , LongLong , String , or 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.

See also
canConvert(), convert()

Definition at line 2675 of file qvariant.cpp.

Referenced by QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QOCIResultPrivate::bindValue(), copyArgument(), QStyledItemDelegate::displayText(), QOCICols::execBatch(), QSortFilterProxyModel::lessThan(), QStandardItem::operator<(), QVariantToVARIANT(), QVariantToVoidStar(), streamDebug(), QSystemLocalePrivate::toCurrencyString(), QPatternist::AtomicValue::toXDM(), QItemDelegatePrivate::valueToText(), and variantToString().

2676 {
2677  return qNumVariantToHelper<qulonglong>(d, handler, ok, d.data.ull);
2678 }
static const Handler * handler
Definition: qvariant.h:419
Private d
Definition: qvariant.h:417

◆ toUrl()

QUrl QVariant::toUrl ( ) const

◆ type()

QVariant::Type QVariant::type ( ) const

Returns the storage type of the value stored in the variant.

Although this function is declared as returning QVariant::Type, the return value should be interpreted as QMetaType::Type. In particular, QVariant::UserType is returned here only if the value is equal or greater than QMetaType::User.

Note that return values in the ranges QVariant::Char through QVariant::RegExp and QVariant::Font through QVariant::Transform correspond to the values in the ranges QMetaType::QChar through QMetaType::QRegExp and QMetaType::QFont through QMetaType::QQuaternion.

Pay particular attention when working with char and QChar variants. Note that there is no QVariant constructor specifically for type char, but there is one for QChar. For a variant of type QChar, this function returns QVariant::Char, which is the same as QMetaType::QChar, but for a variant of type char, this function returns QMetaType::Char, which is not the same as QVariant::Char.

Also note that the types void*, long, short, unsigned long, unsigned short, unsigned char, float, QObject*, and QWidget* are represented in QMetaType::Type but not in QVariant::Type, and they can be returned by this function. However, they are considered to be user defined types when tested against QVariant::Type.

To test whether an instance of QVariant contains a data type that is compatible with the data type you are interested in, use canConvert().

Definition at line 1901 of file qvariant.cpp.

Referenced by QPageSetupWidget::_q_paperSizeChanged(), QFontDatabasePrivate::addQPF2File(), Maemo::IcdPrivate::addrinfo(), QDBusMarshaller::appendVariantInternal(), Maemo::appendVariantToDBusMessage(), QTextHtmlParserNode::applyBackgroundImage(), QStyleSheetStyleSelector::attribute(), QOCIResultPrivate::bindValue(), QCss::Declaration::brushValues(), QCss::Declaration::colorValues(), Maemo::constantVariantList(), create(), createArrayBuffer(), QAccessibleAbstractSpinBox::currentValue(), QItemDelegate::decoration(), do_dbus_call(), QAxBase::dynamicCall(), QPatternist::VariableLoader::evaluateSequence(), QDB2Result::exec(), QSQLiteResult::exec(), QSymSQLResult::exec(), QODBCResult::exec(), QSqlResult::exec(), QTextHtmlExporter::findUrlForImage(), QDeclarativeEnginePrivate::formatTime(), QSqlDriver::formatValue(), QComboMenuDelegate::getStyleOption(), QIBaseResult::gotoNext(), headerValue(), QTextHtmlParser::importStyleSheet(), QDateTimeEditPrivate::init(), QStyledItemDelegate::initStyleOption(), QGraphicsView::inputMethodQuery(), QGraphicsScene::inputMethodQuery(), QPlainTextEdit::inputMethodQuery(), QTextEdit::inputMethodQuery(), QGraphicsTextItem::inputMethodQuery(), QGraphicsProxyWidgetPrivate::inputMethodQueryHelper(), QPatternist::VariableLoader::isSameType(), QComboBoxPrivate::itemIcon(), QAbstractItemView::keyPressEvent(), QSortFilterProxyModel::lessThan(), QTextDocument::loadResource(), macFormatCurrency(), macValue(), operator*(), operator+(), operator-(), operator/(), operator<<(), QOCIResultPrivate::outValues(), QItemDelegate::paint(), qCreateParamString(), qOraOutValue(), qtValue(), QVariantToVARIANT(), QVariantToVoidStar(), QItemDelegate::rect(), QPlatformFontDatabase::registerQPF2Font(), QTextEditPrivate::relayoutDocument(), QTextEdit::resizeEvent(), QInternalMimeData::retrieveData(), QMimeDataPrivate::retrieveTypedData(), save(), Maemo::IcdPrivate::scan(), QWinSettingsPrivate::set(), QStandardItem::setData(), QUrlModel::setData(), QTiffHandler::setOption(), QStyleSheetStyle::setProperties(), QDeclarativeValueTypeScriptClass::setProperty(), QTextBrowserPrivate::setSource(), QPageSetupWidget::setupPrinter(), Maemo::IcdPrivate::state(), Maemo::IcdPrivate::statistics(), streamDebug(), QSystemLocalePrivate::toCurrencyString(), toUrl(), ShaderEffectItem::updateEffectState(), QMimeData::urls(), QDeclarativeEngineDebugService::valueContents(), QAbstractSpinBoxPrivate::variantCompare(), QScript::variantProtoFuncValueOf(), VARIANTToQVariant(), Maemo::variantToSignature(), QSettingsPrivate::variantToString(), Maemo::IAPConfPrivate::variantToValue(), QMYSQLResult::virtual_hook(), QMetaProperty::write(), and QConfFileSettingsPrivate::writeIniFile().

1902 {
1903  return d.type >= QMetaType::User ? UserType : static_cast<Type>(d.type);
1904 }
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
Private d
Definition: qvariant.h:417

◆ typeName()

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 1984 of file qvariant.cpp.

Referenced by QScript::callQtMethod(), QDBusConnectionPrivate::deliverCall(), QAxBase::dynamicCallHelper(), QScriptEnginePrivate::jscValueToVariant(), QAxServerBase::Load(), operator+(), operator-(), operator<<(), QDBusAbstractInterfacePrivate::property(), qDBusReplyFill(), QVariantToVARIANT(), QAxServerBase::Save(), QNetworkHeadersPrivate::setCookedHeader(), ShaderEffectItem::setSource(), QTest::toString(), QPatternist::AtomicValue::toXDM(), QAbstractSpinBoxPrivate::variantCompare(), QScript::variantFromValue(), variantHash(), QScript::variantProtoFuncToString(), variantToString(), and QMetaProperty::write().

1985 {
1986  return typeToName(Type(d.type));
1987 }
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
Private d
Definition: qvariant.h:417

◆ typeToName()

const char * QVariant::typeToName ( Type  typ)
static

Converts the enum representation of the storage type, typ, to its string representation.

Returns a null pointer if the type is QVariant::Invalid or doesn't exist.

Definition at line 2008 of file qvariant.cpp.

Referenced by QDBusMarshaller::append(), QDBusMarshaller::appendVariantInternal(), QDBusMarshaller::beginArray(), QDBusMarshaller::beginMap(), QDBusArgumentPrivate::createSignature(), QDBusMetaObjectGenerator::findType(), generateInterfaceXml(), operator<<(), qDBusReplyFill(), QDeclarativeCompiler::testLiteralAssignment(), and typeName().

2009 {
2010  if (typ == Invalid)
2011  return 0;
2012  if (typ == UserType)
2013  return "UserType";
2014 
2015  return QMetaType::typeName(typ);
2016 }
static const char * typeName(int type)
Returns the type name associated with the given type, or 0 if no matching type was found...
Definition: qmetatype.cpp:406

◆ userType()

int QVariant::userType ( ) const

Returns the storage type of the value stored in the variant.

For non-user types, this is the same as type().

See also
type()

Definition at line 1913 of file qvariant.cpp.

Referenced by QTextCharFormat::anchorName(), QTextCharFormat::anchorNames(), QPatternist::VariableLoader::announceExternalVariable(), QDBusMarshaller::append(), QDBusMarshaller::appendRegisteredType(), QDBusMarshaller::appendVariantInternal(), QTextFormat::boolProperty(), QTextFormat::brushProperty(), QScript::callQtMethod(), QTextFormat::colorProperty(), QDeclarativeGestureAreaParser::compile(), QDeclarativeConnectionsParser::compile(), QDeclarativePropertyChangesParser::compileList(), QDeclarativeListModelParser::compileProperty(), QDeclarativeContextPrivate::context_at(), QDeclarativeContextPrivate::context_count(), QScriptEnginePrivate::convertValue(), QDeclarativePropertyAnimationPrivate::convertVariant(), copyArgument(), QStyledItemDelegate::createEditor(), QItemDelegate::createEditor(), QPatternist::URILoader::createRequest(), QDBusArgumentPrivate::createSignature(), QDeclarativeEnginePrivate::darker(), QDBusConnectionPrivate::deliverCall(), QStyledItemDelegate::displayText(), do_dbus_call(), QTextFormat::doubleProperty(), QPatternist::VariableLoader::evaluateSequence(), headerValue(), QDeclarativeKeysAttached::inputMethodQuery(), QTextFormat::intProperty(), QPatternist::VariableLoader::isSameType(), QPatternist::VariableLoader::itemForName(), QScriptEnginePrivate::jscValueFromVariant(), QTextFormat::lengthVectorProperty(), QSortFilterProxyModel::lessThan(), QDeclarativeEnginePrivate::lighter(), QDeclarativeObjectMethodScriptClass::matchScore(), QScriptEnginePrivate::newVariant(), QTextFormat::objectIndex(), QStandardItem::operator<(), QTextTableData::paddingProperty(), QTextFormat::penProperty(), QDBusConnectionPrivate::prepareReply(), QDeclarativeObjectMethodScriptClass::property(), QDeclarativeContextScriptClass::property(), QDBusAbstractInterfacePrivate::property(), qDBusReplyFill(), qvariant_cast(), save(), QDeclarativeEnginePrivate::scriptValueFromVariant(), QStyledItemDelegate::setEditorData(), QItemDelegate::setEditorData(), QDeclarativeListAccessor::setList(), QStyledItemDelegate::setModelData(), QItemDelegate::setModelData(), QDeclarativeObjectScriptClass::setProperty(), streamDebug(), QTextFormat::stringProperty(), QDeclarativeEnginePrivate::tint(), QDeclarativeMetaType::toQObject(), QScriptEnginePrivate::toQObject(), QDeclarativeEnginePrivate::toQObject(), QTest::toString(), QPatternist::AtomicValue::toXDM(), typeOfVariant(), QDeclarativeBinding::update(), QPropertyAnimationPrivate::updateProperty(), QDeclarativeEngineDebugService::valueContents(), QItemDelegatePrivate::valueToText(), variantHash(), variantToQObject(), QDeclarativeWorkerScriptEnginePrivate::variantToScriptValue(), variantToString(), QDeclarativePropertyPrivate::write(), QMetaProperty::write(), QDeclarativePropertyPrivate::writeEnumProperty(), writeProperty(), and QDeclarativeVMEMetaObject::writeVarProperty().

1914 {
1915  return d.type;
1916 }
Private d
Definition: qvariant.h:417

◆ value()

template<typename T >
T QVariant::value ( ) const
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, default-constructed value will be returned.

If the type T is supported by QVariant, this function behaves exactly as toString(), toInt() etc.

Example:

MyCustomStruct c;
if (v.canConvert<MyCustomStruct>())
c = v.value<MyCustomStruct>();
v = 7;
int i = v.value<int>(); // same as v.toInt()
QString s = v.value<QString>(); // same as v.toString(), s is now "7"
MyCustomStruct c2 = v.value<MyCustomStruct>(); // conversion failed, c2 is empty
See also
setValue(), fromValue(), canConvert()

Definition at line 332 of file qvariant.h.

Referenced by QNetworkManagerInterfaceDeviceWireless::activeAccessPoint(), QNetworkManagerInterface::activeConnections(), QNetworkReply::attribute(), QPaintBuffer::commandDescription(), QNetworkManagerConnectionActive::connection(), copyArgument(), QDeclarativeEnginePrivate::darker(), QDeclarativeEngineDebugPrivate::decode(), QNetworkManagerConnectionActive::devices(), QOfonoNetworkRegistrationInterface::getCellId(), QOfonoNetworkRegistrationInterface::getLac(), QNetworkReply::header(), QSortFilterProxyModel::headerData(), QDeclarativeVisualDataModelDataMetaObject::initialValue(), QNetworkManagerInterfaceDevice::ip4config(), QDeclarativeBasePositioner::itemChange(), QDeclarativeItem::itemChange(), QDeclarativeEnginePrivate::lighter(), QFontEngineQPA::maxCharWidth(), QFontEngineQPF::maxCharWidth(), QFontEngineQPA::minLeftBearing(), QFontEngineQPF::minLeftBearing(), QFontEngineQPA::minRightBearing(), QFontEngineQPF::minRightBearing(), operator<<(), operator>>(), QPainterReplayer::process(), QTreeWidgetItem::read(), QSvgIOHandler::setOption(), QNetworkManagerConnectionActive::specificObject(), QDeclarativeEnginePrivate::tint(), QPatternist::AtomicValue::toXDM(), QPatternist::VariableLoader::valueFor(), QLocale::weekdays(), and QConfFileSettingsPrivate::writeIniFile().

333  { return qvariant_cast<T>(*this); }
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

Friends and Related Functions

◆ operator!=()

bool operator!= ( const QVariant v1,
const QVariant v2 
)
related

Returns false if v1 and v2 are equal; otherwise returns true.

Warning
This function doesn't support custom types registered with qRegisterMetaType().

◆ operator<<

Q_CORE_EXPORT QDebug operator<< ( QDebug  ,
const QVariant  
)
friend

Definition at line 3108 of file qvariant.cpp.

3109 {
3110 #ifndef Q_BROKEN_DEBUG_STREAM
3111  dbg.nospace() << "QVariant(" << v.typeName() << ", ";
3112  QVariant::handler->debugStream(dbg, v);
3113  dbg.nospace() << ')';
3114  return dbg.space();
3115 #else
3116  qWarning("This compiler doesn't support streaming QVariant to QDebug");
3117  return dbg;
3118  Q_UNUSED(v);
3119 #endif
3120 }
QDebug & nospace()
Clears the stream&#39;s internal flag that records whether the last character was a space and returns a r...
Definition: qdebug.h:92
static const Handler * handler
Definition: qvariant.h:419
Q_CORE_EXPORT void qWarning(const char *,...)
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
QDebug & space()
Writes a space character to the debug stream and returns a reference to the stream.
Definition: qdebug.h:91
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ operator== [1/2]

bool operator== ( const QVariant ,
const QVariantComparisonHelper &   
)
friend

◆ operator==() [2/2]

bool operator== ( const QVariant v1,
const QVariant v2 
)
related

Returns true if v1 and v2 are equal; otherwise returns false.

Warning
This function doesn't support custom types registered with qRegisterMetaType().

◆ qRegisterGuiVariant

int qRegisterGuiVariant ( )
friend

Definition at line 811 of file qguivariant.cpp.

812 {
816  return 1;
817 }
const QVariant::Handler qt_gui_variant_handler
static const QMetaTypeGuiHelper qVariantGuiHelper[]
Q_CORE_EXPORT const QMetaTypeGuiHelper * qMetaTypeGuiHelper
Definition: qmetatype.cpp:346
static const Handler * handler
Definition: qvariant.h:419
static const QVariant::Handler * qt_guivariant_last_handler

◆ qUnregisterGuiVariant

int qUnregisterGuiVariant ( )
friend

Definition at line 820 of file qguivariant.cpp.

821 {
823  qMetaTypeGuiHelper = 0;
824  return 1;
825 }
Q_CORE_EXPORT const QMetaTypeGuiHelper * qMetaTypeGuiHelper
Definition: qmetatype.cpp:346
static const Handler * handler
Definition: qvariant.h:419
static const QVariant::Handler * qt_guivariant_last_handler

◆ qvariant_cast()

T qvariant_cast ( const QVariant value)
related

Returns the given value converted to the template type T.

This function is equivalent to QVariant::value().

See also
QVariant::value()

Definition at line 571 of file qvariant.h.

Referenced by do_dbus_call(), getImage(), getPixmap(), qDBusPropertySet(), qDBusReplyFill(), QVariantToVARIANT(), streamDebug(), and variantToString().

572 {
573  const int vid = qMetaTypeId<T>(static_cast<T *>(0));
574  if (vid == v.userType())
575  return *reinterpret_cast<const T *>(v.constData());
576  if (vid < int(QMetaType::User)) {
577  T t;
578  if (qvariant_cast_helper(v, QVariant::Type(vid), &t))
579  return t;
580  }
581  return T();
582 }
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
friend bool qvariant_cast_helper(const QVariant &, QVariant::Type, void *)
Definition: qvariant.h:447

◆ qvariant_cast_helper

bool qvariant_cast_helper ( const QVariant v,
QVariant::Type  tp,
void *  ptr 
)
friend

Definition at line 447 of file qvariant.h.

448 { return QVariant::handler->convert(&v.d, tp, ptr, 0); }
static const Handler * handler
Definition: qvariant.h:419
const T * ptr(const T &t)
Private d
Definition: qvariant.h:417

◆ qVariantCanConvert()

bool qVariantCanConvert ( const QVariant value)
related

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).

Note
This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.
See also
QVariant::canConvert()

Definition at line 597 of file qvariant.h.

598 { return variant.template canConvert<T>(); }
const char * variant

◆ qVariantFromValue()

QVariant qVariantFromValue ( const T &  value)
related

Returns a variant containing a copy of the given value with template type T.

This function is equivalent to QVariant::fromValue(value).

Note
This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.

For example, a QObject pointer can be stored in a variant with the following code:

QObject *object = getObjectFromSomewhere();
See also
QVariant::fromValue()

Definition at line 451 of file qvariant.h.

452 {
453  return QVariant(qMetaTypeId<T>(reinterpret_cast<T *>(0)), &t, QTypeInfo<T>::isPointer);
454 }
QVariant()
Constructs an invalid variant.
Definition: qvariant.h:484

◆ QVariantHash()

QVariantHash
related

Synonym for QHash<QString, QVariant>.

Since
4.5

◆ QVariantList()

QVariantList
related

Synonym for QList<QVariant>.

Referenced by VARIANTToQVariant().

◆ QVariantMap()

QVariantMap
related

◆ qVariantSetValue()

void qVariantSetValue ( QVariant variant,
const T &  value 
)
related

Sets the contents of the given variant to a copy of the value with the specified template type T.

This function is equivalent to QVariant::setValue(value).

Note
This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.
See also
QVariant::setValue()

Definition at line 460 of file qvariant.h.

461 {
462  //if possible we reuse the current QVariant private
463  const uint type = qMetaTypeId<T>(reinterpret_cast<T *>(0));
464  QVariant::Private &d = v.data_ptr();
465  if (v.isDetached() && (type == d.type || (type <= uint(QVariant::Char) && d.type <= uint(QVariant::Char)))) {
466  d.type = type;
467  d.is_null = false;
468  T *old = reinterpret_cast<T*>(d.is_shared ? d.data.shared->ptr : &d.data.ptr);
470  old->~T();
471  new (old) T(t); //call the copy constructor
472  } else {
474  }
475 }
QVariant()
Constructs an invalid variant.
Definition: qvariant.h:484
unsigned int uint
Definition: qglobal.h:996
Private d
Definition: qvariant.h:417
Type type() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1901

◆ qVariantValue()

T qVariantValue ( const QVariant value)
related

Returns the given value converted to the template type T.

This function is equivalent to QVariant::value<T>(value).

Note
This function was provided as a workaround for MSVC 6 which did not support member template functions. It is advised to use the other form in new code.
See also
QVariant::value(), qvariant_cast()

Definition at line 593 of file qvariant.h.

594 { return qvariant_cast<T>(variant); }
const char * variant
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571

Properties

◆ d

Private QVariant::d
protected

◆ handler

const QVariant::Handler * QVariant::handler = &qt_kernel_variant_handler
staticprotected

The documentation for this class was generated from the following files: