QVariant Class Reference |
Constant | Value | Description |
---|---|---|
QVariant::Invalid | 0 | no type |
QVariant::BitArray | 13 | a QBitArray |
QVariant::ByteArray | 12 | a QByteArray |
QVariant::Bitmap | 73 | a QBitmap |
QVariant::Bool | 1 | a bool |
QVariant::Brush | 66 | a QBrush |
QVariant::Color | 67 | a QColor |
QVariant::Cursor | 74 | a QCursor |
QVariant::Date | 14 | a QDate |
QVariant::DateTime | 16 | a QDateTime |
QVariant::Double | 6 | a double |
QVariant::Font | 64 | a QFont |
QVariant::Icon | 69 | a QIcon |
QVariant::Image | 70 | a QImage |
QVariant::Int | 2 | an int |
QVariant::KeySequence | 76 | a QKeySequence |
QVariant::LineF | 24 | a QLineF |
QVariant::Line | 23 | a QLine |
QVariant::List | 9 | a QVariantList (QList<QVariant>) |
QVariant::LongLong | 4 | a long long |
QVariant::ULongLong | 5 | an unsigned long long |
QVariant::Map | 8 | a QVariantMap (QMap<QString, QVariant>) |
QVariant::Palette | 68 | a QPalette |
QVariant::Pen | 77 | a QPen |
QVariant::Pixmap | 65 | a QPixmap |
QVariant::Point | 25 | a QPoint |
QVariant::PointF | 26 | a QPointF |
QVariant::Polygon | 71 | a QPolygon |
QVariant::Rect | 19 | a QRect |
QVariant::RectF | 20 | a QRectF |
QVariant::Region | 72 | a QRegion |
QVariant::Size | 21 | a QSize |
QVariant::SizeF | 22 | a QSizeF |
QVariant::SizePolicy | 75 | a QSizePolicy |
QVariant::String | 10 | a QString |
QVariant::StringList | 11 | a QStringList |
QVariant::Time | 15 | a QTime |
QVariant::UInt | 3 | an unsigned int |
QVariant::TextLength | 78 | a QTextLength |
QVariant::TextFormat | 79 | a QTextFormat |
QVariant::Char | 7 | a QChar |
QVariant::Locale | 18 | a QLocale |
QVariant::Url | 17 | a QUrl |
QVariant::PointArray | Polygon | a QPointArray |
QVariant::UserType | 127 | Base value for user-defined types. |
Constructs an invalid variant.
Constructs a null variant of type type.
Constructs a copy of the variant, p, passed as the argument to this constructor.
Reads the variant from the data stream, s.
Constructs a new variant with an integer value, val.
Constructs a new variant with an unsigned integer value, val.
Constructs a new variant with a long long integer value, val.
Constructs a new variant with an unsigned long long integer value, val.
Constructs a new variant with a boolean value, val. The integer argument is a dummy, necessary for compatibility with some compilers.
Constructs a new variant with a floating point value, val.
Constructs a new variant with a C-string value of val if val is non-null. The variant creates a deep copy of val.
If val is null, the resulting variant has type Invalid.
Constructs a new variant with a bytearray value, val.
Constructs a new variant with a bitarray value, val.
Constructs a new variant with a string value, val.
Constructs a new variant with a string value, val.
Constructs a new variant with a string list value, val.
Constructs a new variant with a char value, c.
Constructs a new variant with a date value, val.
Constructs a new variant with a time value, val.
Constructs a new variant with a date/time value, val.
Constructs a new variant with a list value, val.
Constructs a new variant with a map of QVariants, val.
Constructs a new variant with a size value of val.
Constructs a new variant with a size value of val.
Constructs a new variant with a point value of val.
Constructs a new variant with a point value of val.
Constructs a new variant with a line value of val.
Constructs a new variant with a line value of val.
Constructs a new variant with a rect value of val.
Constructs a new variant with a rect value of val.
Constructs a new variant with a url value of val.
Constructs a new variant with a locale value, l.
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().
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 | Double, Int, UInt, LongLong, ULongLong |
Color | String |
Date | String, DateTime |
DateTime | String, Date, Time |
Double | String, Int, Bool, UInt |
Font | String |
Int | String, Double, Bool, UInt |
List | StringList (if the list contains strings or something that can be cast to a string) |
String | CString, Int, UInt, Bool, Double, Date, Time, DateTime, KeySequence, Font, Color |
CString | String |
StringList | List |
Time | String |
UInt | String, Double, Bool, Int |
KeySequence | String, Int |
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
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().
Convert this variant to type Invalid and free up any resources used.
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().
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() and value().
Returns true if this is a NULL variant, false otherwise.
Returns true if the storage type of this variant is not QVariant::Invalid; otherwise returns false.
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.
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(), and canConvert().
Returns the variant as a QBitArray if the variant has type() BitArray; otherwise returns an empty bitarray.
Returns the variant as a bool if the variant has type() Bool.
Returns true if the variant has type Int, UInt or Double and its 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.
Returns the variant as a QByteArray if the variant has type() ByteArray; otherwise returns an empty bytearray.
Returns the variant as a QChar if the variant has type() Char or contains a numeric value; otherwise returns an invalid QChar.
Returns the variant as a QDate if the variant has type() Date, DateTime or String; otherwise returns an invalid date.
Note that if the type() is String an invalid date will be returned if the string cannot be parsed as a Qt::ISODate format date.
Returns the variant as a QDateTime if the variant has type() DateTime, Date or String; otherwise returns an invalid date/time.
Note that 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.
Returns the variant as a double if the variant has type() String, ByteArray, Double, Int, UInt, LongLong, ULongLong or Bool; 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.
Returns the variant as an int if the variant has type() String, Int, UInt, Double, Bool or KeySequence; 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().
Returns the variant as a QLine if the variant has type() Line; otherwise returns an invalid QLine.
Returns the variant as a QLineF if the variant has type() LineF; otherwise returns an invalid QLineF.
Returns the variant as a QVariantList if the variant has type() List or StringList; otherwise returns an empty list.
Note that if you want to iterate over the list, you should iterate over a copy, e.g.
QVariantList list = myVariant.toList(); QVariantList::Iterator it = list.begin(); while(it != list.end()) { myProcessing(*it); ++it; }
Returns the variant as a QLocale if the variant has type() Locale; otherwise returns an invalid QLocale.
Returns the variant as a long long int if the variant has type() LongLong, ULongLong, any type allowing a toInt() conversion; 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().
Returns the variant as a QMap<QString, QVariant> if the variant has type() Map; otherwise returns an empty map.
Note that if you want to iterate over the map, you should iterate over a copy, e.g.
QVariantMap map = myVariant.toMap(); QVariantMap::Iterator it = map.begin(); while(it != map.end()) { myProcessing(*it); ++it; }
Returns the variant as a QPoint if the variant has type() Point; otherwise returns a null QPoint.
Returns the variant as a QPointF if the variant has type() Point or PointF; otherwise returns a null QPointF.
Returns the variant as a QRect if the variant has type() Rect; otherwise returns an invalid QRect.
Returns the variant as a QRectF if the variant has type() Rect or RectF; otherwise returns an invalid QRectF.
Returns the variant as a QSize if the variant has type() Size or SizeF; otherwise returns an invalid QSize.
Returns the variant as a QSizeF if the variant has type() SizeF or Size; otherwise returns an invalid QSizeF.
Returns the variant as a QString if the variant has type() String, ByteArray, Int, UInt, Bool, Double, Date, Time, DateTime, KeySequence, Font or Color; otherwise returns an empty string.
Returns the variant as a QStringList if the variant has type() StringList or List of a type that can be converted to QString; otherwise returns an empty list.
Returns the variant as a QTime if the variant has type() Time, DateTime or String; otherwise returns an invalid time.
Note that if the type() is String an invalid time will be returned if the string cannot be parsed as a Qt::ISODate format time.
Returns the variant as an unsigned int if the variant has type() String, ByteArray, UInt, Int, Double, or Bool; 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.
Returns the variant as as an unsigned long long int if the variant has type() LongLong, ULongLong, any type allowing a toUInt() conversion; 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().
Returns the variant as a QUrl if the variant has type() Url; otherwise returns an invalid QUrl.
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.
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.
Converts the enum representation of the storage type, typ, to its string representation.
Returns the storage type of the value stored in the variant. For non-user types, this is the same as type().
See also type().
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(), and canConvert().
Compares this QVariant with v and returns true if they are not equal; otherwise returns false.
Assigns the value of the variant variant to this variant.
Compares this QVariant with v and returns true if they are equal; otherwise returns false.
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().
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.
See also QVariant::fromValue().
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().
Returns the given value converted to the template type T.
This function is equivalent to 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() and qvariant_cast().
Returns the given value converted to the template type T.
This function is equivalent to qVariantValue().
See also qVariantValue() and QVariant::value().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns false if v1 and v2 are equal; otherwise returns true.
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
Returns true if v1 and v2 are equal; otherwise returns false.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.0 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com