QVariant Class Reference

#include <qvariant.h>

Inheritance diagram for QVariant:

Inheritance graph
[legend]
Collaboration diagram for QVariant:

Collaboration graph
[legend]
List of all members.

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
        v = QVariant(QStringList());

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 have a defined type with no value set.

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

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

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 \c toColor() function. Instead, you can use the QVariant::value() or the qVariantValue() template function. For example: @code QVariant variant; ... QColor color = variant.value<QColor>(); \endcode The inverse conversion (e.g., from QColor to QVariant) is automatic for all data types supported by QVariant, including GUI-related types: @code QColor color = palette().background().color(); QVariant variant = color; \endcode \sa QMetaType Definition at line 75 of file qvariant.h.

Public Types

enum  Type
typedef void(*) f_construct (Private *, const void *)
typedef void(*) f_clear (Private *)
typedef bool(*) f_null (const Private *)
typedef void(*) f_load (Private *, QDataStream &)
typedef void(*) f_save (const Private *, QDataStream &)
typedef bool(*) f_compare (const Private *, const Private *)
typedef bool(*) f_convert (const QVariant::Private *d, Type t, void *, bool *)
typedef bool(*) f_canConvert (const QVariant::Private *d, Type t)
typedef void(*) f_debugStream (QDebug, const QVariant &)

Public Member Functions

 QVariant ()
 ~QVariant ()
 QVariant (Type type)
 QVariant (int typeOrUserType, const void *copy)
 QVariant (const QVariant &other)
 QVariant (QDataStream &s)
 QVariant (int i)
 QVariant (uint ui)
 QVariant (qlonglong ll)
 QVariant (qulonglong ull)
 QVariant (bool b)
 QVariant (double d)
QT_ASCII_CAST_WARN_CONSTRUCTOR QVariant (const char *str)
 QVariant (const QByteArray &bytearray)
 QVariant (const QBitArray &bitarray)
 QVariant (const QString &string)
 QVariant (const QLatin1String &string)
 QVariant (const QStringList &stringlist)
 QVariant (const QChar &qchar)
 QVariant (const QDate &date)
 QVariant (const QTime &time)
 QVariant (const QDateTime &datetime)
 QVariant (const QList< QVariant > &list)
 QVariant (const QMap< QString, QVariant > &map)
 QVariant (const QSize &size)
 QVariant (const QSizeF &size)
 QVariant (const QPoint &pt)
 QVariant (const QPointF &pt)
 QVariant (const QLine &line)
 QVariant (const QLineF &line)
 QVariant (const QRect &rect)
 QVariant (const QRectF &rect)
 QVariant (const QUrl &url)
 QVariant (const QLocale &locale)
 QVariant (const QRegExp &regExp)
 QVariant (Qt::GlobalColor color)
QVariantoperator= (const QVariant &other)
Type type () const
int userType () const
const char * typeName () const
bool canConvert (Type t) const
bool convert (Type t)
bool isValid () const
bool isNull () const
void clear ()
void detach ()
bool isDetached () const
int toInt (bool *ok=0) const
uint toUInt (bool *ok=0) const
qlonglong toLongLong (bool *ok=0) const
qulonglong toULongLong (bool *ok=0) const
bool toBool () const
double toDouble (bool *ok=0) const
QByteArray toByteArray () const
QBitArray toBitArray () const
QString toString () const
QStringList toStringList () const
QChar toChar () const
QDate toDate () const
QTime toTime () const
QDateTime toDateTime () const
QList< QVarianttoList () const
QMap< QString, QVarianttoMap () const
QPoint toPoint () const
QPointF toPointF () const
QRect toRect () const
QSize toSize () const
QSizeF toSizeF () const
QLine toLine () const
QLineF toLineF () const
QRectF toRectF () const
QUrl toUrl () const
QLocale toLocale () const
QRegExp toRegExp () const
void load (QDataStream &ds)
void save (QDataStream &ds) const
void * data ()
const void * constData () const
const void * data () const
template<typename T>
void setValue (const T &value)
template<typename T>
value () const
template<typename T>
bool canConvert () const
bool operator== (const QVariant &v) const
bool operator!= (const QVariant &v) const

Static Public Member Functions

static const char * typeToName (Type type)
static Type nameToType (const char *name)
template<typename T>
static QVariant fromValue (const T &value)

Protected Member Functions

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

Protected Attributes

Private d

Static Protected Attributes

static const Handlerhandler

Private Member Functions

 QVariant (bool, int)

Friends

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

Related Functions

(Note that these are not member functions.)

bool operator== (const QVariant &v1, const QVariant &v2)
bool operator!= (const QVariant &v1, const QVariant &v2)
QVariant qVariantFromValue (const T &value)
void qVariantSetValue (QVariant &variant, const T &value)
qvariant_cast (const QVariant &value)
qVariantValue (const QVariant &value)
bool qVariantCanConvert (const QVariant &value)
 QVariantList
 QVariantMap

Classes

struct  Handler
struct  Private
struct  PrivateShared


Member Typedef Documentation

typedef void(*) QVariant::f_construct(Private *, const void *)

Definition at line 331 of file qvariant.h.

typedef void(*) QVariant::f_clear(Private *)

Definition at line 332 of file qvariant.h.

typedef bool(*) QVariant::f_null(const Private *)

Definition at line 333 of file qvariant.h.

typedef void(*) QVariant::f_load(Private *, QDataStream &)

Definition at line 335 of file qvariant.h.

typedef void(*) QVariant::f_save(const Private *, QDataStream &)

Definition at line 336 of file qvariant.h.

typedef bool(*) QVariant::f_compare(const Private *, const Private *)

Definition at line 338 of file qvariant.h.

typedef bool(*) QVariant::f_convert(const QVariant::Private *d, Type t, void *, bool *)

Definition at line 339 of file qvariant.h.

typedef bool(*) QVariant::f_canConvert(const QVariant::Private *d, Type t)

Definition at line 340 of file qvariant.h.

typedef void(*) QVariant::f_debugStream(QDebug, const QVariant &)

Definition at line 341 of file qvariant.h.


Member Enumeration Documentation

enum QVariant::Type

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

Invalid no type BitArray a QBitArray Bitmap a QBitmap Bool a bool Brush a QBrush ByteArray a QByteArray Char a QChar Color a QColor Cursor a QCursor Date a QDate DateTime a QDateTime Double a double Font a QFont Icon a QIcon Image a QImage Int an int KeySequence a QKeySequence Line a QLine LineF a QLineF List a QVariantList Locale a QLocale LongLong a qlonglong Map a QVariantMap Matrix a QMatrix Palette a QPalette Pen a QPen Pixmap a QPixmap Point a QPoint PointArray a QPointArray PointF a QPointF Polygon a QPolygon Rect a QRect RectF a QRectF RegExp a QRegExp Region a QRegion Size a QSize SizeF a QSizeF SizePolicy a QSizePolicy String a QString StringList a QStringList TextFormat a QTextFormat TextLength a QTextLength Time a QTime UInt a uint ULongLong a qulonglong Url a QUrl

UserType Base value for user-defined types.

CString ColorGroup IconSet LastGuiType LastCoreType LastType

Definition at line 78 of file qvariant.h.

00078               {
00079         Invalid = 0,
00080 
00081         Bool = 1,
00082         Int = 2,
00083         UInt = 3,
00084         LongLong = 4,
00085         ULongLong = 5,
00086         Double = 6,
00087         Char = 7,
00088         Map = 8,
00089         List = 9,
00090         String = 10,
00091         StringList = 11,
00092         ByteArray = 12,
00093         BitArray = 13,
00094         Date = 14,
00095         Time = 15,
00096         DateTime = 16,
00097         Url = 17,
00098         Locale = 18,
00099         Rect = 19,
00100         RectF = 20,
00101         Size = 21,
00102         SizeF = 22,
00103         Line = 23,
00104         LineF = 24,
00105         Point = 25,
00106         PointF = 26,
00107   RegExp = 27,
00108         LastCoreType = RegExp,
00109 
00110         // value 62 is internally reserved
00111 #ifdef QT3_SUPPORT
00112         ColorGroup = 63,
00113 #endif
00114         Font = 64,
00115         Pixmap = 65,
00116         Brush = 66,
00117         Color = 67,
00118         Palette = 68,
00119         Icon = 69,
00120         Image = 70,
00121         Polygon = 71,
00122         Region = 72,
00123         Bitmap = 73,
00124         Cursor = 74,
00125         SizePolicy = 75,
00126         KeySequence = 76,
00127         Pen = 77,
00128         TextLength = 78,
00129         TextFormat = 79,
00130         Matrix = 80,
00131         LastGuiType = Matrix,
00132 
00133         UserType = 127,
00134 #ifdef QT3_SUPPORT
00135         IconSet = Icon,
00136         CString = ByteArray,
00137         PointArray = Polygon,
00138 #endif
00139         LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type
00140     };


Constructor & Destructor Documentation

QVariant::QVariant (  )  [inline]

Constructs an invalid variant.

Definition at line 418 of file qvariant.h.

Referenced by save().

00418 {}

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

References Char, QVariant::Handler::clear, d, QVariant::Private::data, QBasicAtomic::deref(), handler, QVariant::Private::is_shared, QVariant::PrivateShared::ref, QVariant::Private::Data::shared, and QVariant::Private::type.

01254 {
01255     if (d.type > Char && (!d.is_shared || !d.data.shared->ref.deref()))
01256         handler->clear(&d);
01257 }

Here is the call graph for this function:

QVariant::QVariant ( Type  type  ) 

Constructs a null variant of type type.

Definition at line 1493 of file qvariant.cpp.

References create().

01494 { create(type, 0); }

Here is the call graph for this function:

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 qVariantFromValue() instead to construct variants from the pointer types represented by QMetaType::VoidStar, QMetaType::QObjectStar and QMetaType::QWidgetStar.

See also:
qVariantFromValue(), Type

Definition at line 1495 of file qvariant.cpp.

References create(), d, and QVariant::Private::is_null.

01496 { create(typeOrUserType, copy); d.is_null = false; }

Here is the call graph for this function:

QVariant::QVariant ( const QVariant p  ) 

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

Definition at line 1266 of file qvariant.cpp.

References Char, QVariant::Handler::construct, d, QVariant::Private::data, handler, QVariant::Private::is_shared, p, QVariant::PrivateShared::ref, QBasicAtomic::ref(), and QVariant::Private::Data::shared.

01267     : d(p.d)
01268 {
01269     if (d.is_shared) {
01270         d.data.shared->ref.ref();
01271     } else if (p.d.type > Char) {
01272         handler->construct(&d, p.constData());
01273         d.is_null = p.d.is_null;
01274     }
01275 }

Here is the call graph for this function:

QVariant::QVariant ( QDataStream s  ) 

Reads the variant from the data stream, s.

Definition at line 1281 of file qvariant.cpp.

References d, QVariant::Private::is_null, and s.

01282 {
01283     d.is_null = true;
01284     s >> *this;
01285 }

QVariant::QVariant ( int  val  ) 

Constructs a new variant with an integer value, val.

Definition at line 1497 of file qvariant.cpp.

References d, QVariant::Private::data, QVariant::Private::Data::i, Int, QVariant::Private::is_null, and QVariant::Private::type.

01498 { d.is_null = false; d.type = Int; d.data.i = val; }

QVariant::QVariant ( uint  val  ) 

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

Definition at line 1499 of file qvariant.cpp.

References d, QVariant::Private::data, QVariant::Private::is_null, QVariant::Private::type, QVariant::Private::Data::u, and UInt.

01500 { d.is_null = false; d.type = UInt; d.data.u = val; }

QVariant::QVariant ( qlonglong  val  ) 

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

Definition at line 1501 of file qvariant.cpp.

References d, QVariant::Private::data, QVariant::Private::is_null, QVariant::Private::Data::ll, LongLong, and QVariant::Private::type.

01502 { d.is_null = false; d.type = LongLong; d.data.ll = val; }

QVariant::QVariant ( qulonglong  val  ) 

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

Definition at line 1503 of file qvariant.cpp.

References d, QVariant::Private::data, QVariant::Private::is_null, QVariant::Private::type, QVariant::Private::Data::ull, and ULongLong.

01504 { d.is_null = false; d.type = ULongLong; d.data.ull = val; }

QVariant::QVariant ( bool  val  ) 

Constructs a new variant with a boolean value, val. The integer argument is a dummy, necessary for compatibility with some compilers.

Definition at line 1505 of file qvariant.cpp.

References QVariant::Private::Data::b, Bool, d, QVariant::Private::data, QVariant::Private::is_null, and QVariant::Private::type.

01506 { d.is_null = false; d.type = Bool; d.data.b = val; }

QVariant::QVariant ( double  val  ) 

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

Definition at line 1507 of file qvariant.cpp.

References QVariant::Private::Data::d, d, QVariant::Private::data, Double, QVariant::Private::is_null, and QVariant::Private::type.

01508 { d.is_null = false; d.type = Double; d.data.d = val; }

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

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

See also:
QTextCodec::setCodecForCStrings()

Definition at line 1314 of file qvariant.cpp.

References create(), QString::fromAscii(), s, and String.

01315 {
01316     QString s = QString::fromAscii(val);
01317     create(String, &s);
01318 }

Here is the call graph for this function:

QVariant::QVariant ( const QByteArray val  ) 

Constructs a new variant with a bytearray value, val.

Definition at line 1510 of file qvariant.cpp.

References ByteArray, create(), and val.

01511 { create(ByteArray, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QBitArray val  ) 

Constructs a new variant with a bitarray value, val.

Definition at line 1512 of file qvariant.cpp.

References BitArray, create(), and val.

01513 { create(BitArray, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QString val  ) 

Constructs a new variant with a string value, val.

Definition at line 1514 of file qvariant.cpp.

References create(), String, and val.

01515 { create(String, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QLatin1String val  ) 

Constructs a new variant with a string value, val.

Definition at line 1518 of file qvariant.cpp.

References create(), String, and val.

01519 { QString str(val); create(String, &str); }

Here is the call graph for this function:

QVariant::QVariant ( const QStringList val  ) 

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

Definition at line 1520 of file qvariant.cpp.

References create(), StringList, and val.

01521 { create(StringList, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QChar c  ) 

Constructs a new variant with a char value, c.

Definition at line 1516 of file qvariant.cpp.

References Char, create(), and val.

01517 { create (Char, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QDate val  ) 

Constructs a new variant with a date value, val.

Definition at line 1523 of file qvariant.cpp.

References create(), Date, and val.

01524 { create(Date, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QTime val  ) 

Constructs a new variant with a time value, val.

Definition at line 1525 of file qvariant.cpp.

References create(), Time, and val.

01526 { create(Time, &val); }

Here is the call graph for this function:

QVariant::QVariant ( const QDateTime val  ) 

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

Definition at line 1527 of file qvariant.cpp.

References create(), DateTime, and val.

01528 { create(DateTime, &val); }

Here is the call graph for this function:

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

Constructs a new variant with a list value, val.

Definition at line 1529 of file qvariant.cpp.

References create().

01530 { create(List, &list); }

Here is the call graph for this function:

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

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

Definition at line 1531 of file qvariant.cpp.

References create(), and Map.

01532 { create(Map, &map); }

Here is the call graph for this function:

QVariant::QVariant ( const QSize val  ) 

Constructs a new variant with a size value of val.

Definition at line 1540 of file qvariant.cpp.

References create(), and s.

01540 { create(Size, &s); }

Here is the call graph for this function:

QVariant::QVariant ( const QSizeF val  ) 

Constructs a new variant with a size value of val.

Definition at line 1541 of file qvariant.cpp.

References create(), s, and SizeF.

01541 { create(SizeF, &s); }

Here is the call graph for this function:

QVariant::QVariant ( const QPoint val  ) 

Constructs a new variant with a point value of val.

Definition at line 1534 of file qvariant.cpp.

References create().

01534 { create(Point, &pt); }

Here is the call graph for this function:

QVariant::QVariant ( const QPointF val  ) 

Constructs a new variant with a point value of val.

Definition at line 1535 of file qvariant.cpp.

References create(), and PointF.

01535 { create (PointF, &pt); }

Here is the call graph for this function:

QVariant::QVariant ( const QLine val  ) 

Constructs a new variant with a line value of val.

Definition at line 1538 of file qvariant.cpp.

References create(), and l.

01538 { create (Line, &l); }

Here is the call graph for this function:

QVariant::QVariant ( const QLineF val  ) 

Constructs a new variant with a line value of val.

Definition at line 1537 of file qvariant.cpp.

References create(), l, and LineF.

01537 { create (LineF, &l); }

Here is the call graph for this function:

QVariant::QVariant ( const QRect val  ) 

Constructs a new variant with a rect value of val.

Definition at line 1539 of file qvariant.cpp.

References create().

01539 { create(Rect, &r); }

Here is the call graph for this function:

QVariant::QVariant ( const QRectF val  ) 

Constructs a new variant with a rect value of val.

Definition at line 1536 of file qvariant.cpp.

References create(), and RectF.

01536 { create (RectF, &r); }

Here is the call graph for this function:

QVariant::QVariant ( const QUrl val  ) 

Constructs a new variant with a url value of val.

Definition at line 1543 of file qvariant.cpp.

References create(), u, and Url.

01543 { create(Url, &u); }

Here is the call graph for this function:

QVariant::QVariant ( const QLocale l  ) 

Constructs a new variant with a locale value, l.

Definition at line 1544 of file qvariant.cpp.

References create(), l, and Locale.

01544 { create(Locale, &l); }

Here is the call graph for this function:

QVariant::QVariant ( const QRegExp regExp  ) 

Constructs a new variant with the regexp value regExp.

Definition at line 1545 of file qvariant.cpp.

References create(), and RegExp.

01545 { create(RegExp, &regExp); }

Here is the call graph for this function:

QVariant::QVariant ( Qt::GlobalColor  color  ) 

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

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

References create().

01546 { create(62, &color); }

Here is the call graph for this function:

QVariant::QVariant ( bool  b,
int  dummy 
) [inline, private]

Use the QVariant(bool) constructor instead.

Definition at line 388 of file qvariant.h.

00388 { Q_ASSERT(false); }


Member Function Documentation

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

Assigns the value of the variant variant to this variant.

Definition at line 1574 of file qvariant.cpp.

References Char, clear(), QVariant::Handler::construct, d, handler, QVariant::Private::is_null, QVariant::Private::type, and variant.

Referenced by QDBusVariant::setVariant().

01575 {
01576     if (this == &variant)
01577         return *this;
01578 
01579     clear();
01580     if (variant.d.is_shared) {
01581         variant.d.data.shared->ref.ref();
01582         d = variant.d;
01583     } else if (variant.d.type > Char) {
01584         d.type = variant.d.type;
01585         handler->construct(&d, variant.constData());
01586         d.is_null = variant.d.is_null;
01587     } else {
01588         d = variant.d;
01589     }
01590 
01591     return *this;
01592 }

Here is the call graph for this function:

QVariant::Type QVariant::type (  )  const

Returns the storage type of the value stored in the variant. Usually it's best to test with canConvert() whether the variant can deliver the data type you are interested in.

Definition at line 1554 of file qvariant.cpp.

References d, QVariant::Private::type, QMetaType::User, and UserType.

Referenced by FormBuilderPrivate::applyProperties(), QTextFormat::boolProperty(), QTextFormat::brushProperty(), QDateTimeParser::checkIntermediate(), QTextFormat::colorProperty(), QAbstractFormBuilder::computeProperties(), createArrayBuffer(), VariantDelegate::createEditor(), Q3EditorFactory::createEditor(), qdesigner_internal::QDesignerResource::createIconProperty(), QAbstractFormBuilder::createProperty(), QDateTimeParser::dateTimeCompare(), QTextFormat::doubleProperty(), QSqlTableModelPrivate::exec(), QSqlResult::exec(), QGraphicsItemPrivate::extra(), QSqlDriver::formatValue(), QComboMenuDelegate::getStyleOption(), TrackerClient::httpRequestDone(), QTextHtmlParser::importStyleSheet(), QGraphicsTextItem::inputMethodQuery(), QTextEdit::inputMethodQuery(), qdesigner_internal::ResourceEditor::insertEmptyComboItem(), QTextFormat::intProperty(), QComboBox::itemIcon(), QTextFormat::lengthVectorProperty(), QSortFilterProxyModel::lessThan(), MySortFilterProxyModel::lessThan(), QTextDocument::loadResource(), QTextFormat::objectIndex(), operator *(), operator+(), operator-(), operator/(), QTextFormat::penProperty(), qdesigner_internal::ResourceEditor::removeEmptyComboItem(), QMimeDataPrivate::retrieveTypedData(), save(), qdesigner_internal::ResourceEditor::setCurrentIndex(), qdesigner_internal::ConnectionModel::setData(), QDesignerPropertySheet::setFakeProperty(), VariantDelegate::setModelData(), QDateTimeEditPrivate::stepBy(), streamDebug(), QTextFormat::stringProperty(), Q3SqlCursor::sync(), QAbstractSpinBoxPrivate::variantCompare(), QSettingsPrivate::variantToString(), and QMetaProperty::write().

01555 {
01556     return d.type >= QMetaType::User ? UserType : static_cast<Type>(d.type);
01557 }

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

References d, and QVariant::Private::type.

Referenced by QDBusMarshaller::appendRegisteredType(), QDBusMarshaller::appendVariantInternal(), QDBusArgumentPrivate::createSignature(), debugVariant(), QDBusConnectionPrivate::deliverCall(), placeCall(), prepareReply(), qDBusReplyFill(), qvariant_cast(), save(), QItemDelegate::setEditorData(), and QItemDelegate::setModelData().

01567 {
01568     return d.type;
01569 }

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

References d, QVariant::Private::type, and typeToName().

Referenced by QDateTimeParser::dateTimeCompare(), debugVariant(), operator+(), operator-(), operator<<(), and QAbstractSpinBoxPrivate::variantCompare().

01626 {
01627     return typeToName(Type(d.type));
01628 }

Here is the call graph for this function:

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 DateTime, String UInt Bool, Char, Double, Int, LongLong, String, ULongLong ULongLong Bool, Char, Double, Int, LongLong, String, UInt

See also:
convert()

Definition at line 2394 of file qvariant.cpp.

References Bitmap, Brush, ByteArray, QMetaType::Char, Color, d, QMetaType::Float, Font, Image, Int, KeySequence, LastCoreType, QMetaType::Long, Pixmap, qCanConvertMatrix, QMetaType::Short, String, QVariant::Private::type, QMetaType::UChar, QMetaType::ULong, and QMetaType::UShort.

Referenced by cmp(), convert(), qdesigner_internal::dirItem(), and QDBusViewer::dumpMessage().

02395 {
02396     if (d.type == uint(t))
02397         return true;
02398 
02399     if (d.type > QVariant::LastCoreType || t > QVariant::LastCoreType) {
02400         switch (uint(t)) {
02401         case QVariant::Int:
02402             return d.type == QVariant::KeySequence;
02403         case QVariant::Image:
02404             return d.type == QVariant::Pixmap || d.type == QVariant::Bitmap;
02405         case QVariant::Pixmap:
02406             return d.type == QVariant::Image || d.type == QVariant::Bitmap
02407                               || d.type == QVariant::Brush;
02408         case QVariant::Bitmap:
02409             return d.type == QVariant::Pixmap || d.type == QVariant::Image;
02410         case QVariant::ByteArray:
02411             return d.type == QVariant::Color;
02412         case QVariant::String:
02413             return d.type == QVariant::KeySequence || d.type == QVariant::Font
02414                               || d.type == QVariant::Color;
02415         case QVariant::KeySequence:
02416             return d.type == QVariant::String || d.type == QVariant::Int;
02417         case QVariant::Font:
02418             return d.type == QVariant::String;
02419         case QVariant::Color:
02420             return d.type == QVariant::String || d.type == QVariant::ByteArray
02421                               || d.type == QVariant::Brush;
02422         case QVariant::Brush:
02423             return d.type == QVariant::Color || d.type == QVariant::Pixmap;
02424         case QMetaType::Char:
02425         case QMetaType::UChar:
02426         case QMetaType::Long:
02427         case QMetaType::ULong:
02428         case QMetaType::Short:
02429         case QMetaType::UShort:
02430         case QMetaType::Float:
02431             return qCanConvertMatrix[QVariant::Int] & (1 << d.type) || d.type == QVariant::Int;
02432         default:
02433             return false;
02434         }
02435     }
02436 
02437     return qCanConvertMatrix[t] & (1 << d.type);
02438 }

bool QVariant::convert ( Type  t  ) 

Casts the variant to the requested type. If the cast cannot be done, the variant is set to the default value of the requested type (e.g. an empty string if the requested type t is QVariant::String, an empty point array if the requested type t is QVariant::Polygon, etc). Returns true if the current type of the variant was successfully cast; otherwise returns false.

See also:
canConvert()

Definition at line 2451 of file qvariant.cpp.

References canConvert(), clear(), QVariant::Handler::convert, create(), d, data(), handler, QVariant::Private::is_null, isNull(), and QVariant::Private::type.

Referenced by QDBusViewer::callMethod(), cmp(), QIBaseResult::gotoNext(), parseColorValue(), QMimeDataPrivate::retrieveTypedData(), and QMetaProperty::write().

02452 {
02453     if (d.type == uint(t))
02454         return true;
02455 
02456     QVariant oldValue = *this;
02457 
02458     clear();
02459     if (!oldValue.canConvert(t))
02460         return false;
02461 
02462     create(t, 0);
02463     if (oldValue.isNull())
02464         return false;
02465 
02466     bool isOk = true;
02467     if (!handler->convert(&oldValue.d, t, data(), &isOk))
02468         isOk = false;
02469     d.is_null = !isOk;
02470     return isOk;
02471 }

Here is the call graph for this function:

bool QVariant::isValid (  )  const [inline]

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

Definition at line 419 of file qvariant.h.

References d, Invalid, and QVariant::Private::type.

Referenced by QDBusAbstractInterface::call(), QSqlTableModel::data(), NewForm::on_treeWidget_itemActivated(), QHeaderView::paintSection(), QTextDocument::resource(), QHeaderView::sectionSizeFromContents(), QTreeWidgetItem::setData(), QPrinter::setOutputFormat(), QSqlDriver::sqlStatement(), and QHeaderView::viewportEvent().

00419 { return d.type != Invalid; }

bool QVariant::isNull (  )  const

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

Definition at line 2582 of file qvariant.cpp.

References d, handler, and QVariant::Handler::isNull.

Referenced by QFormBuilder::applyProperties(), QAbstractFormBuilder::applyProperties(), qdesigner_internal::QDesignerFormBuilder::applyProperties(), QAbstractSpinBoxPrivate::bound(), convert(), QLocale::dateFormat(), QLocale::dayName(), QSqlResult::exec(), QSqlCachedResult::isNull(), QSqlField::isNull(), QODBCResult::isNull(), QTextDocument::loadResource(), QLocale::monthName(), operator<<(), qMakeFieldInfo(), QSqlTableModelPrivate::setRecord(), Ping::start(), QLocale::timeFormat(), QLocale::toString(), and QLocalePrivate::updateSystemPrivate().

02583 {
02584     return handler->isNull(&d);
02585 }

void QVariant::clear (  ) 

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

Definition at line 1634 of file qvariant.cpp.

References QVariant::Handler::clear, d, QVariant::Private::data, QBasicAtomic::deref(), handler, Invalid, QVariant::Private::is_null, QVariant::Private::is_shared, QVariant::PrivateShared::ref, QVariant::Private::Data::shared, and QVariant::Private::type.

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

01635 {
01636     if (!d.is_shared || !d.data.shared->ref.deref())
01637         handler->clear(&d);
01638     d.type = Invalid;
01639     d.is_null = true;
01640     d.is_shared = false;
01641 }

Here is the call graph for this function:

void QVariant::detach (  ) 

Definition at line 1600 of file qvariant.cpp.

References QVariant::Handler::clear, constData(), QVariant::Handler::construct, d, QVariant::Private::data, QBasicAtomic::deref(), handler, QVariant::Private::is_shared, qAtomicSetPtr(), QVariant::PrivateShared::ref, QVariant::Private::Data::shared, and QVariant::Private::type.

Referenced by data().

01601 {
01602     if (!d.is_shared || d.data.shared->ref == 1)
01603         return;
01604 
01605     Private dd;
01606     dd.type = d.type;
01607     handler->construct(&dd, constData());
01608     dd.data.shared = qAtomicSetPtr(&d.data.shared, dd.data.shared);
01609     if (!dd.data.shared->ref.deref())
01610         handler->clear(&dd);
01611 }

Here is the call graph for this function:

bool QVariant::isDetached (  )  const [inline]

Definition at line 473 of file qvariant.h.

References d, QVariant::Private::data, QVariant::Private::is_shared, QVariant::PrivateShared::ref, and QVariant::Private::Data::shared.

00474 { return !d.is_shared || d.data.shared->ref == 1; }

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.

See also:
canConvert(), convert()

Definition at line 2176 of file qvariant.cpp.

References d, handler, and Int.

Referenced by QCalendarWidgetPrivate::_q_monthChanged(), Q3Signal::activate(), qdesigner_internal::WidgetBoxTreeView::addWidget(), DocumentShape::animate(), PanelShape::animate(), ImageShape::animate(), TitleShape::animate(), qdesigner_internal::QDesignerResource::applyProperties(), QSettings::beginReadArray(), Dialog::buttonsOrientationChanged(), qdesigner_internal::WidgetBoxTreeView::category(), QAbstractFormBuilder::computeProperties(), qdesigner_internal::WidgetBoxTreeView::contextMenuEvent(), qdesigner_internal::QDesignerResource::createProperty(), QAbstractFormBuilder::createProperty(), qdesigner_internal::PropertyEditor::createPropertySheet(), debugVariant(), qdesigner_internal::dirItem(), QSpinBoxPrivate::emitSignals(), Window::fillRuleChanged(), TrackerClient::httpRequestDone(), qdesigner_internal::InPlaceEditor::InPlaceEditor(), qdesigner_internal::ResourceEditor::insertEmptyComboItem(), QTextFormat::intProperty(), qdesigner_internal::InlineEditorModel::isTitle(), QSortFilterProxyModel::lessThan(), Config::load(), MainWindow::loadSettings(), QTextFormat::objectIndex(), TranslationSettingsDialog::on_buttonBox_accepted(), operator *(), operator+(), operator-(), operator/(), DetailsDialog::orderItems(), BookDelegate::paint(), QHeaderView::paintSection(), Q3Signal::parameter(), MetaInfo::parse(), Ui3Reader::parse(), parseColorValue(), parseStyleValue(), QSQLite2Driver::primaryIndex(), QIBaseDriver::primaryIndex(), MainWindow::printPage(), qGetTableInfo(), qMakeFieldInfo(), QPixelTool::QPixelTool(), QIBaseDriver::record(), QPSQLDriver::record(), QTextControlPrivate::rectForPosition(), qdesigner_internal::ResourceEditor::removeEmptyComboItem(), qdesigner_internal::ResourceEditor::setCurrentIndex(), EditableSqlModel::setData(), QDesignerSettings::setGeometryHelper(), qdesigner_internal::IntProperty::setValue(), qdesigner_internal::ListProperty::setValue(), QDBusViewer::showContextMenu(), MainWindow::showFont(), Oubliette::showInventoryItem(), streamDebug(), QPrinter::supportedResolutions(), QSpinBoxPrivate::textFromValue(), QDesignerSettings::uiMode(), QLocalePrivate::updateSystemPrivate(), QSpinBoxPrivate::validateAndInterpret(), and QAbstractSpinBoxPrivate::variantCompare().

02177 {
02178     return qNumVariantToHelper<int>(d, Int, handler, ok, d.data.i);
02179 }

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.

See also:
canConvert(), convert()

Definition at line 2191 of file qvariant.cpp.

References d, handler, and UInt.

Referenced by qdesigner_internal::FlagsProperty::createEditor(), qdesigner_internal::QDesignerResource::createProperty(), QAbstractFormBuilder::createProperty(), debugVariant(), QSortFilterProxyModel::lessThan(), QDBusConnectionInterface::registerService(), qdesigner_internal::AlignmentProperty::setValue(), streamDebug(), and QDBusConnectionInterface::unregisterService().

02192 {
02193     return qNumVariantToHelper<uint>(d, UInt, handler, ok, d.data.u);
02194 }

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

References d, handler, and LongLong.

Referenced by cmp(), QAbstractFormBuilder::createProperty(), debugVariant(), QSortFilterProxyModel::lessThan(), MainWindow::loadSettings(), qdesigner_internal::LongLongProperty::setValue(), and streamDebug().

02207 {
02208     return qNumVariantToHelper<qlonglong>(d, LongLong, handler, ok, d.data.ll);
02209 }

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

References d, handler, and ULongLong.

Referenced by QAbstractFormBuilder::createProperty(), debugVariant(), QSortFilterProxyModel::lessThan(), and streamDebug().

02223 {
02224     return qNumVariantToHelper<qulonglong>(d, ULongLong, handler, ok, d.data.ull);
02225 }

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 and its lower-case content is not empty, "0" or "false"; otherwise returns false.

See also:
canConvert(), convert()

Definition at line 2237 of file qvariant.cpp.

References QVariant::Private::Data::b, Bool, QVariant::Handler::convert, d, QVariant::Private::data, handler, and QVariant::Private::type.

Referenced by PanelShape::animate(), QTextFormat::boolProperty(), QAbstractFormBuilder::createProperty(), debugVariant(), QPSQLDriver::formatValue(), QSqlDriver::formatValue(), Config::load(), DisplayWidget::mouseMoveEvent(), MainWindow::printPage(), QPixelTool::QPixelTool(), QPSPrintEnginePrivate::QPSPrintEnginePrivate(), TrWindow::readConfig(), QPSQLDriver::record(), QGraphicsItem::setEnabled(), QGraphicsItem::setSelected(), qdesigner_internal::BoolProperty::setValue(), QGraphicsItem::setVisible(), MainWindow::showFont(), QDesignerSettings::showNewFormOnStartup(), streamDebug(), and QImageReader::supportsAnimation().

02238 {
02239     if (d.type == Bool)
02240         return d.data.b;
02241 
02242     bool res = false;
02243     handler->convert(&d, Bool, &res, 0);
02244 
02245     return res;
02246 }

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

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

If ok is non-null: {*}{ok} is set to true if the value could be converted to a double; otherwise {*}{ok} is set to false.

See also:
canConvert(), convert()

Definition at line 2258 of file qvariant.cpp.

References d, Double, and handler.

Referenced by PanelShape::animate(), cmp(), compare_recs(), QAbstractFormBuilder::createProperty(), PieView::dataChanged(), debugVariant(), QTextFormat::doubleProperty(), QDoubleSpinBoxPrivate::emitSignals(), QTextDocument::idealWidth(), PieView::indexAt(), PieView::itemRegion(), QSortFilterProxyModel::lessThan(), operator *(), operator+(), operator-(), operator/(), QTableWidgetItem::operator<(), PieView::paintEvent(), parseColorValue(), PieView::rowsAboutToBeRemoved(), PieView::rowsInserted(), qdesigner_internal::DoubleProperty::setValue(), qdesigner_internal::SpinBoxDoubleProperty::setValue(), streamDebug(), QDoubleSpinBoxPrivate::textFromValue(), QDoubleSpinBoxPrivate::validateAndInterpret(), and QAbstractSpinBoxPrivate::variantCompare().

02259 {
02260     return qNumVariantToHelper<double>(d, Double, handler, ok, d.data.d);
02261 }

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

References ByteArray, d, and handler.

Referenced by MainWindow::aboutToShowSaveAsMenu(), Ui3Reader::createLayoutItem(), QAbstractFormBuilder::createProperty(), debugVariant(), QPSQLDriver::formatValue(), QSqlDriver::formatValue(), QODBCDriver::formatValue(), TrackerClient::httpRequestDone(), QTextHtmlParser::importStyleSheet(), Config::load(), QTextDocument::loadResource(), MainWindow::loadSettings(), main(), QDesignerSettings::mainWindowState(), MetaInfo::parse(), TrWindow::readConfig(), streamDebug(), and QSettingsPrivate::variantToString().

01976 {
01977     return qVariantToHelper<QByteArray>(d, ByteArray, handler);
01978 }

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

References BitArray, d, and handler.

02147 {
02148     return qVariantToHelper<QBitArray>(d, BitArray, handler);
02149 }

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

References d, handler, and String.

Referenced by QFileDialogPrivate::_q_autoCompleteFileName(), QFormBuilder::applyProperties(), FormBuilderPrivate::applyProperties(), buddy(), QUnsortedModelEngine::buildIndices(), MainWindow::changeStyle(), MainWindow::checkCurrentStyle(), QDateTimeParser::checkIntermediate(), compare_recs(), qdesigner_internal::ConnectionDelegate::createEditor(), Ui3Reader::createLayoutItem(), QAbstractFormBuilder::createProperty(), SpreadSheetItem::data(), QLocale::dateFormat(), QLocale::dayName(), debugVariant(), qdesigner_internal::FindIconDialog::defaultFilePath(), qdesigner_internal::FindIconDialog::defaultQrcPath(), QSortedModelEngine::filter(), QCompletionEngine::filterHistory(), Q3DataTable::find(), qdesigner_internal::FindIconDialog::FindIconDialog(), QDBusConnectionPrivate::findMetaObject(), QSqlDriver::formatValue(), SpreadSheetItem::formula(), XbelGenerator::generateItem(), QDBusConnectionPrivate::getNameOwner(), QImageReaderPrivate::getText(), QTextHtmlParser::importStyleSheet(), Main::init(), QCss::Declaration::intValue(), QCss::ValueExtractor::lengthValue(), QSortFilterProxyModel::lessThan(), MySortFilterProxyModel::lessThan(), Config::load(), MainWindow::loadSettings(), HelpDialog::locateContents(), HelpDialog::locateLink(), QPlastiqueStylePrivate::lookupIconTheme(), QAbstractItemModel::match(), QLocale::monthName(), DisplayWidget::mousePressEvent(), NewForm::on_treeWidget_currentItemChanged(), TrPreviewTool::on_viewForms_doubleClicked(), Main::openConfig(), MainWindow::openRecentFile(), qdesigner_internal::SheetDelegate::paint(), QDateTimeParser::parse(), Ui3Reader::parse(), parseColorValue(), parseStyleValue(), QCompleter::pathFromIndex(), placeCall(), qdesigner_internal::FindIconDialog::previousInputBox(), QSQLite2Driver::primaryIndex(), QIBaseDriver::primaryIndex(), QDBusError::QDBusError(), qDBusPropertyGet(), qDBusPropertySet(), qGetTableInfo(), QCss::Declaration::realValue(), QIBaseDriver::record(), QPSQLDriver::record(), qdesigner_internal::InsertWidgetCommand::redo(), qdesigner_internal::SetPropertyCommand::redo(), Main::saveConfig(), qdesigner_internal::ConnectionModel::setData(), qdesigner_internal::QPropertyEditorDelegate::setModelData(), qdesigner_internal::StringProperty::setValue(), HelpDialog::showIndexItemMenu(), Ping::start(), BatchTranslationDialog::startTranslation(), streamDebug(), QTextFormat::stringProperty(), Q3SqlCursor::sync(), QSQLite2Driver::tables(), QSQLiteDriver::tables(), QIBaseDriver::tables(), Q3DataTable::text(), QAccessibleHeader::text(), QAccessibleItemRow::text(), QLocale::timeFormat(), QGraphicsItem::toolTip(), QLocale::toString(), qdesigner_internal::FontProperty::toString(), TrPreviewTool::translationSelected(), qdesigner_internal::SetPropertyCommand::undo(), qdesigner_internal::InsertWidgetCommand::undo(), qdesigner_internal::QDesignerFormWindowCommand::updateBuddies(), Main::updateStatus(), SpreadSheet::updateStatus(), QLocalePrivate::updateSystemPrivate(), QSettingsPrivate::variantToString(), and QHeaderView::viewportEvent().

01902 {
01903     return qVariantToHelper<QString>(d, String, handler);
01904 }

QStringList QVariant::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.

See also:
canConvert(), convert()

Definition at line 1888 of file qvariant.cpp.

References d, handler, and StringList.

Referenced by debugVariant(), Config::defaultProfileExists(), QDBusViewer::dumpMessage(), qdesigner_internal::FindIconDialog::FindIconDialog(), fontPath(), QDesignerSettings::formTemplatePaths(), QLibraryPrivate::isPlugin(), Config::load(), Config::loadDefaultProfile(), parseBrushValue(), parseColorValue(), placeCall(), QDesignerPluginManager::QDesignerPluginManager(), QFactoryLoader::QFactoryLoader(), TrWindow::readConfig(), QDesignerSettings::recentFilesList(), QCss::Declaration::rectValue(), streamDebug(), and MainWindow::updateRecentFileActions().

01889 {
01890     return qVariantToHelper<QStringList>(d, StringList, handler);
01891 }

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

References Char, d, and handler.

Referenced by QAbstractFormBuilder::createProperty(), QSortFilterProxyModel::lessThan(), qdesigner_internal::CharProperty::setValue(), and streamDebug().

02136 {
02137     return qVariantToHelper<QChar>(d, Char, handler);
02138 }

QDate QVariant::toDate (  )  const

Returns the variant as a QDate if the variant has type() Date, DateTime, or String; otherwise returns an invalid date.

If the type() is String, an invalid date will be returned if the string cannot be parsed as a Qt::ISODate format date.

See also:
canConvert(), convert()

Definition at line 1928 of file qvariant.cpp.

References d, Date, and handler.

Referenced by QDateTimeParser::checkIntermediate(), QDateTimeParser::dateTimeCompare(), QDateTimeEditPrivate::emitSignals(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QDateTimeParser::fromString(), QSortFilterProxyModel::lessThan(), operator/(), QDateTimeParser::potentialValue(), qdesigner_internal::DateProperty::setValue(), QDateTimeEditPrivate::stepBy(), streamDebug(), and QAbstractSpinBoxPrivate::variantCompare().

01929 {
01930     return qVariantToHelper<QDate>(d, Date, handler);
01931 }

QTime QVariant::toTime (  )  const

Returns the variant as a QTime if the variant has type() Time, DateTime, or String; otherwise returns an invalid time.

If the type() is String, an invalid time will be returned if the string cannot be parsed as a Qt::ISODate format time.

See also:
canConvert(), convert()

Definition at line 1944 of file qvariant.cpp.

References d, handler, and Time.

Referenced by QDateTimeParser::dateTimeCompare(), QDateTimeEditPrivate::emitSignals(), QPSQLDriver::formatValue(), QSqlDriver::formatValue(), QIBaseDriver::formatValue(), QDateTimeParser::fromString(), QSortFilterProxyModel::lessThan(), qdesigner_internal::TimeProperty::setValue(), streamDebug(), and QAbstractSpinBoxPrivate::variantCompare().

01945 {
01946     return qVariantToHelper<QTime>(d, Time, handler);
01947 }

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

References d, DateTime, and handler.

Referenced by QDateTimeParser::checkIntermediate(), QDateTimeParser::dateTimeCompare(), QDateTimeEditPrivate::emitSignals(), QPSQLDriver::formatValue(), QSqlDriver::formatValue(), QODBCDriver::formatValue(), QIBaseDriver::formatValue(), QSortFilterProxyModel::lessThan(), MySortFilterProxyModel::lessThan(), operator *(), operator+(), operator-(), operator/(), QDateTimeParser::parse(), QDateTimeParser::setDigit(), qdesigner_internal::DateTimeProperty::setValue(), streamDebug(), QDateTimeEditPrivate::textFromValue(), and QAbstractSpinBoxPrivate::variantCompare().

01962 {
01963     return qVariantToHelper<QDateTime>(d, DateTime, handler);
01964 }

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

References d, and handler.

Referenced by createArrayBuffer(), debugVariant(), TrackerClient::httpRequestDone(), QTextFormat::lengthVectorProperty(), and streamDebug().

02270 {
02271     return qVariantToHelper<QVariantList>(d, List, handler);
02272 }

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

References d, handler, and Map.

Referenced by debugVariant(), and streamDebug().

01913 {
01914     return qVariantToHelper<QVariantMap>(d, Map, handler);
01915 }

QPoint QVariant::toPoint (  )  const

Returns the variant as a QPoint if the variant has type() Point or PointF; otherwise returns a null QPoint.

See also:
canConvert(), convert()

Definition at line 1989 of file qvariant.cpp.

References d, and handler.

Referenced by QAbstractFormBuilder::createProperty(), QGraphicsTextItem::inputMethodQuery(), QTextEdit::inputMethodQuery(), PiecesModel::mimeData(), QPixelTool::QPixelTool(), MainWindow::readSettings(), qdesigner_internal::PointProperty::setValue(), PiecesList::startDrag(), and streamDebug().

01990 {
01991     return qVariantToHelper<QPoint>(d, Point, handler);
01992 }

QPointF QVariant::toPointF (  )  const

Returns the variant as a QPointF if the variant has type() Point or PointF; otherwise returns a null QPointF.

See also:
canConvert(), convert()

Definition at line 2080 of file qvariant.cpp.

References d, handler, and PointF.

Referenced by QAbstractFormBuilder::createProperty(), QGraphicsTextItem::inputMethodQuery(), QTextEdit::inputMethodQuery(), QGraphicsItem::setPos(), qdesigner_internal::PointFProperty::setValue(), and streamDebug().

02081 {
02082     return qVariantToHelper<QPointF>(d, PointF, handler);
02083 }

QRect QVariant::toRect (  )  const

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

See also:
canConvert(), convert()

Definition at line 2002 of file qvariant.cpp.

References d, and handler.

Referenced by QAbstractFormBuilder::createProperty(), QDBusViewer::dumpMessage(), QGraphicsTextItem::inputMethodQuery(), QTextEdit::inputMethodQuery(), QKeyMapper::sendKeyEvent(), QDesignerSettings::setGeometryHelper(), qdesigner_internal::RectProperty::setValue(), and streamDebug().

02003 {
02004     return qVariantToHelper<QRect>(d, Rect, handler);
02005 }

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

References d, and handler.

Referenced by QAbstractFormBuilder::createProperty(), QPixelTool::QPixelTool(), MainWindow::readSettings(), qdesigner_internal::SetPropertyCommand::redo(), qdesigner_internal::ResetPropertyCommand::redo(), qdesigner_internal::SizeProperty::setValue(), QImageReader::size(), streamDebug(), qdesigner_internal::SetPropertyCommand::undo(), and qdesigner_internal::ResetPropertyCommand::undo().

02016 {
02017     return qVariantToHelper<QSize>(d, Size, handler);
02018 }

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

References d, handler, and SizeF.

Referenced by QAbstractFormBuilder::createProperty(), qdesigner_internal::SizeFProperty::setValue(), and streamDebug().

02029 {
02030     return qVariantToHelper<QSizeF>(d, SizeF, handler);
02031 }

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

References d, and handler.

Referenced by streamDebug().

02068 {
02069     return qVariantToHelper<QLine>(d, Line, handler);
02070 }

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

References d, handler, and LineF.

Referenced by streamDebug().

02055 {
02056     return qVariantToHelper<QLineF>(d, LineF, handler);
02057 }

QRectF QVariant::toRectF (  )  const

Returns the variant as a QRectF if the variant has type() Rect or RectF; otherwise returns an invalid QRectF.

See also:
canConvert(), convert()

Definition at line 2041 of file qvariant.cpp.

References d, handler, and RectF.

Referenced by QAbstractFormBuilder::createProperty(), QGraphicsTextItem::inputMethodQuery(), QTextEdit::inputMethodQuery(), qdesigner_internal::RectFProperty::setValue(), and streamDebug().

02042 {
02043     return qVariantToHelper<QRectF>(d, RectF, handler);
02044 }

QUrl QVariant::toUrl (  )  const

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

See also:
canConvert(), convert()

Definition at line 2095 of file qvariant.cpp.

References d, handler, and Url.

Referenced by QAbstractFormBuilder::createProperty(), QMimeDataPrivate::retrieveTypedData(), qdesigner_internal::UrlProperty::setValue(), and streamDebug().

02096 {
02097     return qVariantToHelper<QUrl>(d, Url, handler);
02098 }

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

References d, handler, and Locale.

02109 {
02110     return qVariantToHelper<QLocale>(d, Locale, handler);
02111 }

QRegExp QVariant::toRegExp (  )  const

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

See also:
canConvert(), convert()

Definition at line 2122 of file qvariant.cpp.

References d, handler, and RegExp.

02123 {
02124     return qVariantToHelper<QRegExp>(d, RegExp, handler);
02125 }

void QVariant::load ( QDataStream s  ) 

Internal function for loading a variant from stream s. Use the stream operators instead.

Definition at line 1733 of file qvariant.cpp.

References clear(), constData(), create(), d, Invalid, QVariant::Private::is_null, QMetaType::load(), map_from_three, MapFromThreeCount, name, QDataStream::Qt_4_0, QDataStream::Qt_4_2, qWarning(), s, QVariant::Private::type, QMetaType::type(), u, UserType, and x.

01734 {
01735     clear();
01736 
01737     quint32 u;
01738     s >> u;
01739     if (s.version() < QDataStream::Qt_4_0) {
01740         if (u >= MapFromThreeCount)
01741             return;
01742         u = map_from_three[u];
01743     }
01744     qint8 is_null = false;
01745     if (s.version() >= QDataStream::Qt_4_2)
01746         s >> is_null;
01747     if (u >= QVariant::UserType) {
01748         QByteArray name;
01749         s >> name;
01750         u = QMetaType::type(name);
01751         if (!u)
01752             qFatal("QVariant::load(QDataStream &s): type %s unknown to QVariant.", name.data());
01753     }
01754     create(static_cast<int>(u), 0);
01755     d.is_null = is_null;
01756 
01757     if (d.type == QVariant::Invalid) {
01758         // Since we wrote something, we should read something
01759         QString x;
01760         s >> x;
01761         d.is_null = true;
01762         return;
01763     }
01764 
01765     // const cast is save since we operate on a newly constructed variant
01766     if (!QMetaType::load(s, d.type, const_cast<void *>(::constData(d)))) {
01767         Q_ASSERT_X(false, "QVariant::load", "Invalid type to load");
01768         qWarning("QVariant::load: unable to load type %d.", d.type);
01769     }
01770 }

Here is the call graph for this function:

void QVariant::save ( QDataStream s  )  const

Internal function for saving a variant to the stream s. Use the stream operators instead.

Definition at line 1778 of file qvariant.cpp.

References constData(), d, i, Invalid, QVariant::Private::is_null, map_from_three, MapFromThreeCount, QDataStream::Qt_4_0, QDataStream::Qt_4_2, QVariant(), qWarning(), s, QMetaType::save(), tp, type(), QVariant::Private::type, QMetaType::typeName(), UserType, and userType().

01779 {
01780     quint32 tp = type();
01781     if (s.version() < QDataStream::Qt_4_0) {
01782         int i;
01783         for (i = 0; i < MapFromThreeCount; ++i) {
01784             if (map_from_three[i] == tp) {
01785                 tp = i;
01786                 break;
01787             }
01788         }
01789         if (i == MapFromThreeCount) {
01790             s << QVariant();
01791             return;
01792         }
01793     }
01794     s << tp;
01795     if (s.version() >= QDataStream::Qt_4_2)
01796         s << qint8(d.is_null);
01797     if (tp == QVariant::UserType) {
01798         s << QMetaType::typeName(userType());
01799     }
01800 
01801     if (d.type == QVariant::Invalid) {
01802         s << QString();
01803         return;
01804     }
01805 
01806     if (!QMetaType::save(s, d.type, ::constData(d))) {
01807         Q_ASSERT_X(false, "QVariant::save", "Invalid type to save");
01808         qWarning("QVariant::save: unable to save type %d.", d.type);
01809     }
01810 }

Here is the call graph for this function:

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

References Invalid, QMetaType::typeName(), and UserType.

Referenced by QDBusMarshaller::append(), QDBusMarshaller::appendVariantInternal(), assign(), QDBusMarshaller::beginArray(), QDBusMarshaller::beginMap(), QDBusArgumentPrivate::createSignature(), QDBusMetaObjectGenerator::findType(), generateInterfaceXml(), operator<<(), qtTypeName(), Browser::showMetaData(), and typeName().

01650 {
01651     if (typ == Invalid)
01652         return 0;
01653     if (typ == UserType)
01654         return "UserType";
01655 
01656     return QMetaType::typeName(typ);
01657 }

Here is the call graph for this function:

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

References ByteArray, Icon, int, Invalid, LastGuiType, LongLong, QMetaType::type(), ULongLong, and UserType.

Referenced by QDBusViewer::callMethod(), QDBusMetaObjectGenerator::findType(), placeCall(), qDBusNameToTypeId(), QMetaProperty::read(), and QMetaProperty::write().

01668 {
01669     if (!name || !*name)
01670         return Invalid;
01671     if (strcmp(name, "Q3CString") == 0)
01672         return ByteArray;
01673     if (strcmp(name, "Q_LLONG") == 0)
01674         return LongLong;
01675     if (strcmp(name, "Q_ULLONG") == 0)
01676         return ULongLong;
01677     if (strcmp(name, "QIconSet") == 0)
01678         return Icon;
01679     if (strcmp(name, "UserType") == 0)
01680         return UserType;
01681 
01682     int metaType = QMetaType::type(name);
01683     return metaType <= int(LastGuiType) ? QVariant::Type(metaType) : UserType;
01684 }

Here is the call graph for this function:

void * QVariant::data (  ) 

Definition at line 2557 of file qvariant.cpp.

References constData(), d, and detach().

Referenced by convert(), PiecesModel::dropMimeData(), QAbstractTableModel::dropMimeData(), QAbstractListModel::dropMimeData(), QAbstractItemModel::dropMimeData(), QSqlTableModelPrivate::setRecord(), and QMetaProperty::write().

02558 {
02559     detach();
02560     return const_cast<void *>(::constData(d));
02561 }

Here is the call graph for this function:

const void * QVariant::constData (  )  const

Definition at line 2545 of file qvariant.cpp.

References constData(), and d.

Referenced by QDBusMarshaller::appendRegisteredType(), QDBusMarshaller::appendVariantInternal(), QDBusArgumentPrivate::createSignature(), data(), QDBusConnectionPrivate::deliverCall(), detach(), load(), qvariant_cast(), and save().

02546 {
02547     return ::constData(d);
02548 }

Here is the call graph for this function:

const void * QVariant::data (  )  const [inline]

Definition at line 279 of file qvariant.h.

References constData().

00279 { return constData(); }

Here is the call graph for this function:

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:

        QVariant v;

        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>();

Warning:
This function is not available with MSVC 6. Use qVariantSetValue() instead if you need to support that version of the compiler.
See also:
value(), fromValue(), canConvert()

Definition at line 462 of file qvariant.h.

References qVariantSetValue().

Referenced by QSqlResult::exec(), and qdesigner_internal::QPropertyEditorModel::setData().

00463 { qVariantSetValue(*this, avalue); }

Here is the call graph for this function:

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:

        QVariant v;

        MyCustomStruct c;
        if (v.canConvert<MyCustomStruct>())
            c = v.value<MyCustomStruct>(v);

        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

Warning:
This function is not available with MSVC 6. Use qVariantValue() or qvariant_cast() instead if you need to support that version of the compiler.
See also:
setValue(), fromValue(), canConvert()

Definition at line 286 of file qvariant.h.

Referenced by qdesigner_internal::FlagsProperty::createEditor(), QSqlQueryModel::data(), QGraphicsItemPrivate::extra(), QTreeWidgetItem::read(), qdesigner_internal::QPropertyEditorDelegate::setModelData(), and QDateTimeEditPrivate::validateAndInterpret().

00287     { return qVariantValue<T>(*this); }

template<typename T>
static QVariant QVariant::fromValue ( const T &  value  )  [inline, static]

Returns a QVariant containing a copy of value. Behaves exactly like setValue() otherwise.

Example:

        MyCustomStruct s;
        return QVariant::fromValue(s);

Warning:
This function is not available with MSVC 6. Use qVariantFromValue() instead if you need to support that version of the compiler.
See also:
setValue(), value()

Definition at line 290 of file qvariant.h.

References qVariantFromValue().

00291     { return qVariantFromValue(value); }

Here is the call graph for this function:

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

Warning:
This function is not available with MSVC 6. Use qVariantCanConvert() instead if you need to support that version of the compiler.
See also:
convert()

Definition at line 294 of file qvariant.h.

00295     { return qVariantCanConvert<T>(*this); }

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

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

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

Definition at line 357 of file qvariant.h.

References cmp().

00358     { return cmp(v); }

Here is the call graph for this function:

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 359 of file qvariant.h.

References cmp().

00360     { return !cmp(v); }

Here is the call graph for this function:

void QVariant::create ( int  type,
const void *  copy 
) [protected]

Definition at line 1236 of file qvariant.cpp.

References QVariant::Handler::construct, d, handler, and QVariant::Private::type.

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

01237 {
01238     d.type = type;
01239     handler->construct(&d, copy);
01240 }

bool QVariant::cmp ( const QVariant other  )  const [protected]

Definition at line 2526 of file qvariant.cpp.

References canConvert(), QVariant::Handler::compare, convert(), d, handler, qIsFloatingPoint(), qIsNumericType(), toDouble(), toLongLong(), and QVariant::Private::type.

Referenced by operator==().

02527 {
02528     QVariant v2 = v;
02529     if (d.type != v2.d.type) {
02530         if (qIsNumericType(d.type) && qIsNumericType(v.d.type)) {
02531             if (qIsFloatingPoint(d.type) || qIsFloatingPoint(v.d.type))
02532                 return qFuzzyCompare(toDouble(), v.toDouble());
02533             else
02534                 return toLongLong() == v.toLongLong();
02535         }
02536         if (!v2.canConvert(Type(d.type)) || !v2.convert(Type(d.type)))
02537             return false;
02538     }
02539     return handler->compare(&d, &v2.d);
02540 }

Here is the call graph for this function:


Friends And Related Function Documentation

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

Definition at line 399 of file qvariant.h.

00400 { return QVariant::handler->convert(&v.d, tp, ptr, 0); }

int qRegisterGuiVariant (  )  [friend]

Definition at line 620 of file qguivariant.cpp.

00621 {
00622     QVariant::handler = &qt_gui_variant_handler;
00623     qMetaTypeGuiHelper = qVariantGuiHelper;
00624 
00625     return 1;
00626 }

bool operator== ( const QVariant v1,
const QVariantComparisonHelper v2 
) [friend]

Definition at line 495 of file qvariant.h.

00496 {
00497     return v1.cmp(*v2.v);
00498 }

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

Definition at line 2588 of file qvariant.cpp.

02589 {
02590 #ifndef Q_BROKEN_DEBUG_STREAM
02591     dbg.nospace() << "QVariant(" << v.typeName() << ", ";
02592     QVariant::handler->debugStream(dbg, v);
02593     dbg.nospace() << ')';
02594     return dbg.space();
02595 #else
02596     qWarning("This compiler doesn't support streaming QVariant to QDebug");
02597     return dbg;
02598     Q_UNUSED(v);
02599 #endif
02600 }

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

Referenced by QFileInfo::operator!=(), Q3TableSelection::operator!=(), QTextTableCell::operator!=(), QSqlRecord::operator!=(), QDir::operator!=(), QString::operator!=(), QSqlField::operator!=(), QBrush::operator!=(), operator!=(), and QRegExp::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().

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). It is provided as a work-around for MSVC 6, which doesn't support member template functions.

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

    QObject *object = getObjectFromSomewhere();
    QVariant data = qVariantFromValue(object);

See also:
QVariant::fromValue()

Referenced by placeCall(), and qDBusPropertyGet().

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). It is provided as a work-around for MSVC 6, which doesn't support member template functions.

See also:
QVariant::setValue()

Referenced by setValue().

T qvariant_cast ( const QVariant value  )  [related]

Returns the given value converted to the template type {T}.

This function is equivalent to qVariantValue().

See also:
qVariantValue(), QVariant::value()

Definition at line 533 of file qvariant.h.

00534 {
00535     const int vid = qMetaTypeId<T>(static_cast<T *>(0));
00536     if (vid == v.userType())
00537         return *reinterpret_cast<const T *>(v.constData());
00538     if (vid < int(QMetaType::User)) {
00539         T t;
00540         qvariant_cast_helper(v, QVariant::Type(vid), &t);
00541         return t;
00542     }
00543     return T();
00544 }

T qVariantValue ( const QVariant value  )  [related]

Returns the given value converted to the template type {T}.

This function is equivalent to {QVariant::value()}{QVariant::value}<T>(value). It is provided as a work-around for MSVC 6, which doesn't support member template functions.

See also:
QVariant::value(), qvariant_cast()

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). It is provided as a work-around for MSVC 6, which doesn't support member template functions.

See also:
QVariant::canConvert()

QVariantList [related]

Synonym for QList<QVariant>.

Referenced by convert().

QVariantMap [related]

Synonym for QMap<QString, QVariant>.

Referenced by compare().


Member Data Documentation

Private QVariant::d [protected]

Definition at line 369 of file qvariant.h.

Referenced by canConvert(), clear(), cmp(), constData(), convert(), create(), data(), detach(), isDetached(), isNull(), isValid(), load(), operator=(), QVariant(), save(), toBitArray(), toBool(), toByteArray(), toChar(), toDate(), toDateTime(), toDouble(), toInt(), toLine(), toLineF(), toList(), toLocale(), toLongLong(), toMap(), toPoint(), toPointF(), toRect(), toRectF(), toRegExp(), toSize(), toSizeF(), toString(), toStringList(), toTime(), toUInt(), toULongLong(), toUrl(), type(), typeName(), userType(), and ~QVariant().

const QVariant::Handler * QVariant::handler [static, protected]

Definition at line 372 of file qvariant.h.

Referenced by clear(), cmp(), convert(), create(), detach(), isNull(), operator<<(), operator=(), qRegisterGuiVariant(), QVariant(), qvariant_cast_helper(), toBitArray(), toBool(), toByteArray(), toChar(), toDate(), toDateTime(), toDouble(), toInt(), toLine(), toLineF(), toList(), toLocale(), toLongLong(), toMap(), toPoint(), toPointF(), toRect(), toRectF(), toRegExp(), toSize(), toSizeF(), toString(), toStringList(), toTime(), toUInt(), toULongLong(), toUrl(), and ~QVariant().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 19:43:15 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1