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 \l Type enum. See the \l QMetaType documentation
for details.
A Note on GUI Types
Because QVariant is part of the QtCore library, it cannot provide
conversion functions to data types defined in QtGui, such as
QColor, QImage, and QPixmap. In other words, there is no \c
toColor() function. Instead, you can use the QVariant::value() or
the qVariantValue() template function. For example:
QVariant variant;
...
QColor color = variant.value();
The inverse conversion (e.g., from QColor to QVariant) is
automatic for all data types supported by QVariant, including
GUI-related types:
QColor color = palette().background().color();
QVariant variant = color;
Because of Java's introspection, you should only use the QVariant
class when dealing with Qt Jambi classes that requires them.
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I> |
Field Summary |
static int |
BitArray
Java BitArray |
static int |
Bitmap
Java Bitmap |
static int |
Boolean
Java Boolean |
static int |
Brush
Java Brush |
static int |
ByteArray
Java ByteArray |
static int |
Char
Java Char |
static int |
Color
Java Color |
static int |
Cursor
Java Cursor |
static int |
Date
Java Date |
static int |
DateTime
Java DateTime |
static int |
Double
Java Double |
static int |
Font
Java Font |
static int |
Icon
Java Icon |
static int |
Image
Java Image |
static int |
Int
Java Int |
static int |
Invalid
An invalid Java data type |
static int |
KeySequence
Java KeySequence |
static int |
Line
Java Line |
static int |
LineF
Java LineF |
static int |
Locale
Java Locale |
static int |
Long
Java Long |
static int |
Palette
Java Palette |
static int |
Pen
Java Pen |
static int |
Pixmap
Java Pixmap |
static int |
Point
Java Point |
static int |
PointF
Java PointF |
static int |
Polygon
Java Polygon |
static int |
Rect
Java Rect |
static int |
RectF
Java RectF |
static int |
RegExp
Java RegExp |
static int |
Region
Java Region |
static int |
Size
Java Size |
static int |
SizeF
Java SizeF |
static int |
SizePolicy
Java SizePolicy |
static int |
String
Java String |
static int |
StringList
Java StringList |
static int |
TextFormat
Java TextFormat |
static int |
TextLength
Java TextLength |
static int |
Time
Java Time |
static int |
UserType
Java Usertype |
Constructor Summary |
QVariant()
Creates a new QVariant. |
Method Summary |
static boolean |
canConvertToBitArray(java.lang.Object obj)
Returns true if obj can be converted to a bit array. |
static boolean |
canConvertToBoolean(java.lang.Object obj)
Returns true if obj can be converted to boolean. |
static boolean |
canConvertToByteArray(java.lang.Object obj)
Returns true if obj can be converted to a byte array. |
static boolean |
canConvertToChar(java.lang.Object obj)
Returns true if obj can be converted to a char. |
static boolean |
canConvertToDate(java.lang.Object obj)
Returns true if obj can be converted to a QDate. |
static boolean |
canConvertToDateTime(java.lang.Object obj)
Returns true if obj can be converted to a QDateTime. |
static boolean |
canConvertToDouble(java.lang.Object obj)
Returns true if obj can be converted to a double; otherwise,
returns false. |
static boolean |
canConvertToInt(java.lang.Object obj)
Returns true if obj can be converted to an int. |
static boolean |
canConvertToLine(java.lang.Object obj)
Returns true if obj can be converted to a QLine. |
static boolean |
canConvertToLineF(java.lang.Object obj)
Returns true if obj can be converted to a QLineF. |
static boolean |
canConvertToList(java.lang.Object obj)
Returns true if obj can be converted to a list
of type java.util.List. |
static boolean |
canConvertToLocale(java.lang.Object obj)
Returns true if obj can be converted to a QLocale. |
static boolean |
canConvertToLong(java.lang.Object obj)
Returns true if obj can be converted to a long. |
static boolean |
canConvertToMap(java.lang.Object obj)
Returns true if obj can be converted to a map
(java.util.Map). |
static boolean |
canConvertToPoint(java.lang.Object obj)
Returns true if obj can be converted to a QPoint. |
static boolean |
canConvertToPointF(java.lang.Object obj)
Returns true if obj can be converted to a QPointF. |
static boolean |
canConvertToRect(java.lang.Object obj)
Returns true if obj can be converted to a QRect. |
static boolean |
canConvertToRectF(java.lang.Object obj)
Returns true if obj can be converted to a QRectF. |
static boolean |
canConvertToRegExp(java.lang.Object obj)
Returns true if obj can be converted to a QRegExp. |
static boolean |
canConvertToSize(java.lang.Object obj)
Returns true if obj can be converted to a QSize. |
static boolean |
canConvertToSizeF(java.lang.Object obj)
Returns true if obj can be converted to a QSizeF. |
static boolean |
canConvertToString(java.lang.Object obj)
Returns true if obj can be converted to a string; otherwise,
returns false. |
static boolean |
canConvertToTime(java.lang.Object obj)
Returns true if obj can be converted to a QTime. |
static QBitArray |
toBitArray(java.lang.Object obj)
Returns obj as a QBitArray. |
static boolean |
toBoolean(java.lang.Object obj)
Returns the boolean value of obj. |
static QByteArray |
toByteArray(java.lang.Object obj)
Returns obj converted to a QByteArray. |
static char |
toChar(java.lang.Object obj)
Returns the char value of obj |
static QDate |
toDate(java.lang.Object obj)
Returns obj converted to a QDate. |
static QDateTime |
toDateTime(java.lang.Object obj)
Returns obj converted to a QDateTime. |
static double |
toDouble(java.lang.Object obj)
Returns the double value of obj
obj |
static double |
toDouble(java.lang.Object obj,
java.lang.Boolean[] ok)
Returns the double value of obj. |
static int |
toInt(java.lang.Object obj)
Returns the int value of obj. |
static int |
toInt(java.lang.Object obj,
java.lang.Boolean[] ok)
Returns the int value of obj. |
static QLine |
toLine(java.lang.Object obj)
Returns obj as a QLine. |
static QLineF |
toLineF(java.lang.Object obj)
Returns obj converted to a QLineF. |
static java.util.List<java.lang.Object> |
toList(java.lang.Object obj)
Returns obj as a list. |
static QLocale |
toLocale(java.lang.Object obj)
Returns obj converted to a QLocale. |
static long |
toLong(java.lang.Object obj)
Returns the long value of obj |
static long |
toLong(java.lang.Object obj,
java.lang.Boolean[] ok)
Returns the long value of obj. |
static java.util.Map<java.lang.String,java.lang.Object> |
toMap(java.lang.Object obj)
Returns obj as a map. |
static QPoint |
toPoint(java.lang.Object obj)
Returns obj converted to a QPoint. |
static QPointF |
toPointF(java.lang.Object obj)
Returns obj converted to a QPointF. |
static QRect |
toRect(java.lang.Object obj)
Returns obj converted to a QRect. |
static QRectF |
toRectF(java.lang.Object obj)
Returns obj converted to a QPointF. |
static QRegExp |
toRegExp(java.lang.Object obj)
Returns the QRegExp value of obj. |
static QSize |
toSize(java.lang.Object obj)
Returns the QSize value of obj. |
static QSizeF |
toSizeF(java.lang.Object obj)
Returns the QSizeF value of obj. |
static java.lang.String |
toString(java.lang.Object obj)
|
static QTime |
toTime(java.lang.Object obj)
Returns the QTime value of obj. |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Invalid
public static final int Invalid
- An invalid Java data type
- See Also:
- Constant Field Values
Double
public static final int Double
- Java Double
- See Also:
- Constant Field Values
String
public static final int String
- Java String
- See Also:
- Constant Field Values
Boolean
public static final int Boolean
- Java Boolean
- See Also:
- Constant Field Values
ByteArray
public static final int ByteArray
- Java ByteArray
- See Also:
- Constant Field Values
BitArray
public static final int BitArray
- Java BitArray
- See Also:
- Constant Field Values
Char
public static final int Char
- Java Char
- See Also:
- Constant Field Values
Date
public static final int Date
- Java Date
- See Also:
- Constant Field Values
DateTime
public static final int DateTime
- Java DateTime
- See Also:
- Constant Field Values
Int
public static final int Int
- Java Int
- See Also:
- Constant Field Values
Line
public static final int Line
- Java Line
- See Also:
- Constant Field Values
LineF
public static final int LineF
- Java LineF
- See Also:
- Constant Field Values
Locale
public static final int Locale
- Java Locale
- See Also:
- Constant Field Values
Long
public static final int Long
- Java Long
- See Also:
- Constant Field Values
Point
public static final int Point
- Java Point
- See Also:
- Constant Field Values
PointF
public static final int PointF
- Java PointF
- See Also:
- Constant Field Values
Rect
public static final int Rect
- Java Rect
- See Also:
- Constant Field Values
RectF
public static final int RectF
- Java RectF
- See Also:
- Constant Field Values
RegExp
public static final int RegExp
- Java RegExp
- See Also:
- Constant Field Values
Size
public static final int Size
- Java Size
- See Also:
- Constant Field Values
SizeF
public static final int SizeF
- Java SizeF
- See Also:
- Constant Field Values
StringList
public static final int StringList
- Java StringList
- See Also:
- Constant Field Values
Time
public static final int Time
- Java Time
- See Also:
- Constant Field Values
Font
public static final int Font
- Java Font
- See Also:
- Constant Field Values
Pixmap
public static final int Pixmap
- Java Pixmap
- See Also:
- Constant Field Values
Brush
public static final int Brush
- Java Brush
- See Also:
- Constant Field Values
Color
public static final int Color
- Java Color
- See Also:
- Constant Field Values
Palette
public static final int Palette
- Java Palette
- See Also:
- Constant Field Values
Icon
public static final int Icon
- Java Icon
- See Also:
- Constant Field Values
Image
public static final int Image
- Java Image
- See Also:
- Constant Field Values
Polygon
public static final int Polygon
- Java Polygon
- See Also:
- Constant Field Values
Region
public static final int Region
- Java Region
- See Also:
- Constant Field Values
Bitmap
public static final int Bitmap
- Java Bitmap
- See Also:
- Constant Field Values
Cursor
public static final int Cursor
- Java Cursor
- See Also:
- Constant Field Values
SizePolicy
public static final int SizePolicy
- Java SizePolicy
- See Also:
- Constant Field Values
KeySequence
public static final int KeySequence
- Java KeySequence
- See Also:
- Constant Field Values
Pen
public static final int Pen
- Java Pen
- See Also:
- Constant Field Values
TextLength
public static final int TextLength
- Java TextLength
- See Also:
- Constant Field Values
TextFormat
public static final int TextFormat
- Java TextFormat
- See Also:
- Constant Field Values
UserType
public static final int UserType
- Java Usertype
- See Also:
- Constant Field Values
QVariant
public QVariant()
- Creates a new QVariant.
canConvertToDouble
public static boolean canConvertToDouble(java.lang.Object obj)
- Returns true if obj can be converted to a double; otherwise,
returns false.
toDouble
public static double toDouble(java.lang.Object obj)
- Returns the double value of obj
obj
- Returns:
toDouble
public static double toDouble(java.lang.Object obj,
java.lang.Boolean[] ok)
- Returns the double value of obj. If the conversion fails, the
first element in ok will be false; otherwise, it will be
true.
canConvertToString
public static boolean canConvertToString(java.lang.Object obj)
- Returns true if obj can be converted to a string; otherwise,
returns false.
obj
- Returns:
toString
public static java.lang.String toString(java.lang.Object obj)
-
canConvertToBoolean
public static boolean canConvertToBoolean(java.lang.Object obj)
- Returns true if obj can be converted to boolean.
toBoolean
public static boolean toBoolean(java.lang.Object obj)
- Returns the boolean value of obj.
canConvertToByteArray
public static boolean canConvertToByteArray(java.lang.Object obj)
- Returns true if obj can be converted to a byte array.
- Returns:
toByteArray
public static QByteArray toByteArray(java.lang.Object obj)
- Returns obj converted to a QByteArray.
canConvertToBitArray
public static boolean canConvertToBitArray(java.lang.Object obj)
- Returns true if obj can be converted to a bit array.
toBitArray
public static QBitArray toBitArray(java.lang.Object obj)
- Returns obj as a QBitArray.
canConvertToChar
public static boolean canConvertToChar(java.lang.Object obj)
- Returns true if obj can be converted to a char.
toChar
public static char toChar(java.lang.Object obj)
- Returns the char value of obj
canConvertToDate
public static boolean canConvertToDate(java.lang.Object obj)
- Returns true if obj can be converted to a QDate.
toDate
public static QDate toDate(java.lang.Object obj)
- Returns obj converted to a QDate.
canConvertToDateTime
public static boolean canConvertToDateTime(java.lang.Object obj)
- Returns true if obj can be converted to a QDateTime.
toDateTime
public static QDateTime toDateTime(java.lang.Object obj)
- Returns obj converted to a QDateTime.
canConvertToInt
public static boolean canConvertToInt(java.lang.Object obj)
- Returns true if obj can be converted to an int.
toInt
public static int toInt(java.lang.Object obj)
- Returns the int value of obj.
toInt
public static int toInt(java.lang.Object obj,
java.lang.Boolean[] ok)
- Returns the int value of obj. The first element in
ok will be false if the conversion failed.
canConvertToLine
public static boolean canConvertToLine(java.lang.Object obj)
- Returns true if obj can be converted to a QLine.
toLine
public static QLine toLine(java.lang.Object obj)
- Returns obj as a QLine.
canConvertToLineF
public static boolean canConvertToLineF(java.lang.Object obj)
- Returns true if obj can be converted to a QLineF.
toLineF
public static QLineF toLineF(java.lang.Object obj)
- Returns obj converted to a QLineF.
canConvertToLocale
public static boolean canConvertToLocale(java.lang.Object obj)
- Returns true if obj can be converted to a QLocale.
toLocale
public static QLocale toLocale(java.lang.Object obj)
- Returns obj converted to a QLocale.
canConvertToPoint
public static boolean canConvertToPoint(java.lang.Object obj)
- Returns true if obj can be converted to a QPoint.
toPoint
public static QPoint toPoint(java.lang.Object obj)
- Returns obj converted to a QPoint.
canConvertToPointF
public static boolean canConvertToPointF(java.lang.Object obj)
- Returns true if obj can be converted to a QPointF.
toPointF
public static QPointF toPointF(java.lang.Object obj)
- Returns obj converted to a QPointF.
canConvertToRect
public static boolean canConvertToRect(java.lang.Object obj)
- Returns true if obj can be converted to a QRect.
toRect
public static QRect toRect(java.lang.Object obj)
- Returns obj converted to a QRect.
canConvertToRectF
public static boolean canConvertToRectF(java.lang.Object obj)
- Returns true if obj can be converted to a QRectF.
toRectF
public static QRectF toRectF(java.lang.Object obj)
- Returns obj converted to a QPointF.
canConvertToRegExp
public static boolean canConvertToRegExp(java.lang.Object obj)
- Returns true if obj can be converted to a QRegExp.
toRegExp
public static QRegExp toRegExp(java.lang.Object obj)
- Returns the QRegExp value of obj.
canConvertToSize
public static boolean canConvertToSize(java.lang.Object obj)
- Returns true if obj can be converted to a QSize.
toSize
public static QSize toSize(java.lang.Object obj)
- Returns the QSize value of obj.
canConvertToSizeF
public static boolean canConvertToSizeF(java.lang.Object obj)
- Returns true if obj can be converted to a QSizeF.
toSizeF
public static QSizeF toSizeF(java.lang.Object obj)
- Returns the QSizeF value of obj.
canConvertToTime
public static boolean canConvertToTime(java.lang.Object obj)
- Returns true if obj can be converted to a QTime.
toTime
public static QTime toTime(java.lang.Object obj)
- Returns the QTime value of obj.
canConvertToLong
public static boolean canConvertToLong(java.lang.Object obj)
- Returns true if obj can be converted to a long.
toLong
public static long toLong(java.lang.Object obj)
- Returns the long value of obj
toLong
public static long toLong(java.lang.Object obj,
java.lang.Boolean[] ok)
- Returns the long value of obj. The first element in
ok is set to false if the conversion failed.
canConvertToList
public static boolean canConvertToList(java.lang.Object obj)
- Returns true if obj can be converted to a list
of type java.util.List.
toList
public static java.util.List<java.lang.Object> toList(java.lang.Object obj)
- Returns obj as a list.
canConvertToMap
public static boolean canConvertToMap(java.lang.Object obj)
- Returns true if obj can be converted to a map
(java.util.Map).
toMap
public static java.util.Map<java.lang.String,java.lang.Object> toMap(java.lang.Object obj)
- Returns obj as a map.