Qyoto  4.0.5
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Properties
QtCore.QVariant Class Reference

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

Inheritance diagram for QtCore.QVariant:
Collaboration diagram for QtCore.QVariant:

Public Types

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

Public Member Functions

 QVariant ()
 
 
 QVariant (object other)
 
 
 QVariant (QDataStream s)
 
 
 QVariant (QByteArray bytearray)
 
 
 QVariant (QBitArray bitarray)
 
 
 QVariant (QLatin1String @string)
 
 
 QVariant (QChar qchar)
 
 
 QVariant (QDate date)
 
 
 QVariant (QTime time)
 
 
 QVariant (QDateTime datetime)
 
 
 QVariant (QSize size)
 
 
 QVariant (QSizeF size)
 
 
 QVariant (QPoint pt)
 
 
 QVariant (QPointF pt)
 
 
 QVariant (QLine line)
 
 
 QVariant (QLineF line)
 
 
 QVariant (QRect rect)
 
 
 QVariant (QRectF rect)
 
 
 QVariant (QUrl url)
 
 
 QVariant (QLocale locale)
 
 
 QVariant (QRegExp regExp)
 
 
 QVariant (QEasingCurve easing)
 
 
 QVariant (QVariant.Type type)
 
 
 QVariant (int i)
 
 
 QVariant (uint ui)
 
 
 QVariant (long ll)
 
 
 QVariant (ulong ull)
 
 
 QVariant (bool b)
 
 
 QVariant (double d)
 
 
 QVariant (float f)
 
 
 QVariant (string @string)
 
 
 QVariant (Qt.GlobalColor color)
 
 
 QVariant (System.Collections.Generic.List< string > stringlist)
 
 
 QVariant (System.Collections.Generic.List< System.Object > list)
 
 
 QVariant (System.Collections.Generic.Dictionary< System.String, System.Object > map)
 
 
virtual void CreateProxy ()
 
new bool CanConvert (QVariant.Type t)
 
 
new void Clear ()
 
 
new bool Convert (QVariant.Type t)
 
 
new void Detach ()
 
new bool IsDetached ()
 
new bool IsNull ()
 
 
new bool IsValid ()
 
 
new void Load (QDataStream ds)
 
new void Save (QDataStream ds)
 
new void Swap (object other)
 
 
new QBitArray ToBitArray ()
 
 
new bool ToBool ()
 
 
new QByteArray ToByteArray ()
 
 
new QChar ToChar ()
 
 
new QDate ToDate ()
 
 
new QDateTime ToDateTime ()
 
 
new double ToDouble ()
 
 
new double ToDouble (ref bool ok)
 
 
new QEasingCurve ToEasingCurve ()
 
 
new float ToFloat ()
 
 
new float ToFloat (ref bool ok)
 
 
new
System.Collections.Generic.Dictionary
< System.String, System.Object > 
ToHash ()
 
 
new int ToInt ()
 
 
new int ToInt (ref bool ok)
 
 
new QLine ToLine ()
 
 
new QLineF ToLineF ()
 
 
new
System.Collections.Generic.List
< System.Object > 
ToList ()
 
 
new QLocale ToLocale ()
 
 
new long ToLongLong ()
 
 
new long ToLongLong (ref bool ok)
 
 
new
System.Collections.Generic.Dictionary
< System.String, System.Object > 
ToMap ()
 
 
new QPoint ToPoint ()
 
 
new QPointF ToPointF ()
 
 
new double ToReal ()
 
 
new double ToReal (ref bool ok)
 
 
new QRect ToRect ()
 
 
new QRectF ToRectF ()
 
 
new QRegExp ToRegExp ()
 
 
new QSize ToSize ()
 
 
new QSizeF ToSizeF ()
 
 
override string ToString ()
 
 
new
System.Collections.Generic.List
< string > 
ToStringList ()
 
 
new QTime ToTime ()
 
 
new uint ToUInt ()
 
 
new uint ToUInt (ref bool ok)
 
 
new ulong ToULongLong ()
 
 
new ulong ToULongLong (ref bool ok)
 
 
new QUrl ToUrl ()
 
 
new QVariant.Type type ()
 
 
new string TypeName ()
 
 
new int UserType ()
 
 
new void Dispose ()
 

Static Public Member Functions

static QVariant.Type NameToType (string name)
 
 
static string TypeToName (QVariant.Type type)
 
 

Protected Member Functions

 QVariant (System.Type dummy)
 
new bool Cmp (object other)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

virtual System.IntPtr SmokeObject [get, set]
 

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

QVariant x, y(QString()), z(QString(""));

x.convert(QVariant::Int);

// x.isNull() == true

// y.isNull() == true, z.isNull() == false

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

A Note on GUI Types

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

QVariant variant;

...

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

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

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

QVariant variant = color;

Using canConvert() and convert() Consecutively

When using canConvert() and convert() consecutively, it is possible for canConvert() to return true, but convert() to return false. This is typically because canConvert() only reports the general ability of QVariant to convert between types given suitable data; it is still possible to supply data which cannot actually be converted.

For example, canConvert() would return true when called on a variant containing a string because, in principle, QVariant is able to convert strings of numbers to integers. However, if the string contains non-numeric characters, it cannot be converted to an integer, and any attempt to convert it will fail. Hence, it is important to have both functions return true for a successful conversion.

See also QMetaType.

Member Enumeration Documentation

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

Enumerator:
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

EasingCurve 

A QEasingCurve

Font 

A QFont

Hash 

A QVariantHash

Icon 

A QIcon

Image 

A QImage

Int 

An int

Invalid 

No type

KeySequence 

A QKeySequence

LastCoreType 
LastGuiType 
LastType 
Line 

A QLine

LineF 

A QLineF

List 

A QVariantList

Locale 

A QLocale

LongLong 

A qlonglong

Map 

A QVariantMap

Matrix 

A QMatrix(obsolete)

Matrix4x4 

A QMatrix4x4

Palette 

A QPalette

Pen 

A QPen

Pixmap 

A QPixmap

Point 

A QPoint

PointF 

A QPointF

Polygon 

A QPolygon

Quaternion 

A QQuaternion

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

Transform 

A QTransform

UInt 

A uint

ULongLong 

A qulonglong

Url 

A QUrl

UserType 

Base value for user-defined types.

Vector2D 

A QVector2D

Vector3D 

A QVector3D

Vector4D 

A QVector4D

Constructor & Destructor Documentation

QtCore.QVariant.QVariant ( System.Type  dummy)
protected
QtCore.QVariant.QVariant ( )

Constructs an invalid variant.

QtCore.QVariant.QVariant ( object  other)

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

QtCore.QVariant.QVariant ( QDataStream  s)

Reads the variant from the data stream, s.

QtCore.QVariant.QVariant ( QByteArray  bytearray)

Constructs a new variant with a bytearray value, val.

QtCore.QVariant.QVariant ( QBitArray  bitarray)

Constructs a new variant with a bitarray value, val.

QtCore.QVariant.QVariant ( QLatin1String string)

Constructs a new variant with a string value, val.

QtCore.QVariant.QVariant ( QChar  qchar)

Constructs a new variant with a char value, c.

QtCore.QVariant.QVariant ( QDate  date)

Constructs a new variant with a date value, val.

QtCore.QVariant.QVariant ( QTime  time)

Constructs a new variant with a time value, val.

QtCore.QVariant.QVariant ( QDateTime  datetime)

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

QtCore.QVariant.QVariant ( QSize  size)

Constructs a new variant with a size value of val.

QtCore.QVariant.QVariant ( QSizeF  size)

Constructs a new variant with a size value of val.

QtCore.QVariant.QVariant ( QPoint  pt)

Constructs a new variant with a point value of val.

QtCore.QVariant.QVariant ( QPointF  pt)

Constructs a new variant with a point value of val.

QtCore.QVariant.QVariant ( QLine  line)

Constructs a new variant with a line value of val.

QtCore.QVariant.QVariant ( QLineF  line)

Constructs a new variant with a line value of val.

QtCore.QVariant.QVariant ( QRect  rect)

Constructs a new variant with a rect value of val.

QtCore.QVariant.QVariant ( QRectF  rect)

Constructs a new variant with a rect value of val.

QtCore.QVariant.QVariant ( QUrl  url)

Constructs a new variant with a url value of val.

QtCore.QVariant.QVariant ( QLocale  locale)

Constructs a new variant with a locale value, l.

QtCore.QVariant.QVariant ( QRegExp  regExp)

Constructs a new variant with the regexp value regExp.

QtCore.QVariant.QVariant ( QEasingCurve  easing)

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

This function was introduced in Qt 4.7.

QtCore.QVariant.QVariant ( QVariant.Type  type)

Constructs a null variant of type type.

QtCore.QVariant.QVariant ( int  i)

Constructs a new variant with an integer value, val.

QtCore.QVariant.QVariant ( uint  ui)

Constructs an invalid variant.

QtCore.QVariant.QVariant ( long  ll)

Constructs an invalid variant.

QtCore.QVariant.QVariant ( ulong  ull)

Constructs an invalid variant.

QtCore.QVariant.QVariant ( bool  b)

Constructs a new variant with a boolean value, val.

QtCore.QVariant.QVariant ( double  d)

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

QtCore.QVariant.QVariant ( float  f)

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

This function was introduced in Qt 4.6.

QtCore.QVariant.QVariant ( string @  string)

Constructs a new variant with a string value, val.

QtCore.QVariant.QVariant ( Qt.GlobalColor  color)

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.

This function was introduced in Qt 4.2.

QtCore.QVariant.QVariant ( System.Collections.Generic.List< string >  stringlist)

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

QtCore.QVariant.QVariant ( System.Collections.Generic.List< System.Object >  list)

Constructs a new variant with a list value, val.

QtCore.QVariant.QVariant ( System.Collections.Generic.Dictionary< System.String, System.Object >  map)

Constructs an invalid variant.

Member Function Documentation

new bool QtCore.QVariant.CanConvert ( QVariant.Type  t)

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:

TypeAutomatically Cast To

Bool Char, Double, Int, LongLong, String, UInt, ULongLong

ByteArray Double, Int, LongLong, String, UInt, ULongLong

Char Bool, Int, UInt, LongLong, ULongLong

Color String

Date DateTime, String

DateTime Date, String, Time

Double Bool, Int, LongLong, String, UInt, ULongLong

Font String

Int Bool, Char, Double, LongLong, String, UInt, ULongLong

KeySequence Int, String

List StringList (if the list's items can be converted to strings)

LongLong Bool, ByteArray, Char, Double, Int, String, UInt, ULongLong

Point PointF

Rect RectF

String Bool, ByteArray, Char, Color, Date, DateTime, Double, Font, Int, KeySequence, LongLong, StringList, Time, UInt, ULongLong

StringList List, String (if the list contains exactly one item)

Time String

UInt Bool, Char, Double, Int, LongLong, String, ULongLong

ULongLong Bool, Char, Double, Int, LongLong, String, UInt

See also convert().

new void QtCore.QVariant.Clear ( )

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

new bool QtCore.QVariant.Cmp ( object  other)
protected
new bool QtCore.QVariant.Convert ( QVariant.Type  t)

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

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

See also canConvert() and clear().

virtual void QtCore.QVariant.CreateProxy ( )
virtual
new void QtCore.QVariant.Detach ( )
new void QtCore.QVariant.Dispose ( )
new bool QtCore.QVariant.IsDetached ( )
new bool QtCore.QVariant.IsNull ( )

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

new bool QtCore.QVariant.IsValid ( )

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

new void QtCore.QVariant.Load ( QDataStream  ds)
static QVariant.Type QtCore.QVariant.NameToType ( string  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.

new void QtCore.QVariant.Save ( QDataStream  ds)
new void QtCore.QVariant.Swap ( object  other)

Swaps variant other with this variant. This operation is very fast and never fails.

This function was introduced in Qt 4.8.

new QBitArray QtCore.QVariant.ToBitArray ( )

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

See also canConvert() and convert().

new bool QtCore.QVariant.ToBool ( )

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

Returns true if the variant has type() Bool, Char, Double, Int, LongLong, UInt, or ULongLong and the value is non-zero, or if the variant has type String or ByteArray and its lower-case content is not empty, "0" or "false"; otherwise returns false.

See also canConvert() and convert().

new QByteArray QtCore.QVariant.ToByteArray ( )

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

new QChar QtCore.QVariant.ToChar ( )

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

See also canConvert() and convert().

new QDate QtCore.QVariant.ToDate ( )

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

new QDateTime QtCore.QVariant.ToDateTime ( )

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

new double QtCore.QVariant.ToDouble ( )

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

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

new double QtCore.QVariant.ToDouble ( ref bool  ok)

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

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

new QEasingCurve QtCore.QVariant.ToEasingCurve ( )

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

This function was introduced in Qt 4.7.

See also canConvert() and convert().

new float QtCore.QVariant.ToFloat ( )

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

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.

This function was introduced in Qt 4.6.

See also canConvert() and convert().

new float QtCore.QVariant.ToFloat ( ref bool  ok)

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

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.

This function was introduced in Qt 4.6.

See also canConvert() and convert().

new System.Collections.Generic.Dictionary<System.String,System.Object> QtCore.QVariant.ToHash ( )

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

See also canConvert() and convert().

new int QtCore.QVariant.ToInt ( )

Returns the variant as an int if the variant has type() Int, Bool, ByteArray, Char, Double, LongLong, String, UInt, or ULongLong; otherwise returns 0.

If ok is non-null: *ok is set to true if the value could be converted to an int; otherwise *ok is set to false.

Warning: If the value is convertible to a LongLong but is too large to be represented in an int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toInt(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also canConvert() and convert().

new int QtCore.QVariant.ToInt ( ref bool  ok)

Returns the variant as an int if the variant has type() Int, Bool, ByteArray, Char, Double, LongLong, String, UInt, or ULongLong; otherwise returns 0.

If ok is non-null: *ok is set to true if the value could be converted to an int; otherwise *ok is set to false.

Warning: If the value is convertible to a LongLong but is too large to be represented in an int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toInt(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also canConvert() and convert().

new QLine QtCore.QVariant.ToLine ( )

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

See also canConvert() and convert().

new QLineF QtCore.QVariant.ToLineF ( )

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

See also canConvert() and convert().

new System.Collections.Generic.List<System.Object> QtCore.QVariant.ToList ( )

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

See also canConvert() and convert().

new QLocale QtCore.QVariant.ToLocale ( )

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

See also canConvert() and convert().

new long QtCore.QVariant.ToLongLong ( )

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

new long QtCore.QVariant.ToLongLong ( ref bool  ok)

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

new System.Collections.Generic.Dictionary<System.String,System.Object> QtCore.QVariant.ToMap ( )

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

See also canConvert() and convert().

new QPoint QtCore.QVariant.ToPoint ( )

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

See also canConvert() and convert().

new QPointF QtCore.QVariant.ToPointF ( )

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

See also canConvert() and convert().

new double QtCore.QVariant.ToReal ( )

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

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.

This function was introduced in Qt 4.6.

See also canConvert() and convert().

new double QtCore.QVariant.ToReal ( ref bool  ok)

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

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.

This function was introduced in Qt 4.6.

See also canConvert() and convert().

new QRect QtCore.QVariant.ToRect ( )

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

See also canConvert() and convert().

new QRectF QtCore.QVariant.ToRectF ( )

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

See also canConvert() and convert().

new QRegExp QtCore.QVariant.ToRegExp ( )

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

This function was introduced in Qt 4.1.

See also canConvert() and convert().

new QSize QtCore.QVariant.ToSize ( )

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

See also canConvert() and convert().

new QSizeF QtCore.QVariant.ToSizeF ( )

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

See also canConvert() and convert().

override string QtCore.QVariant.ToString ( )

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

new System.Collections.Generic.List<string> QtCore.QVariant.ToStringList ( )

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

new QTime QtCore.QVariant.ToTime ( )

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

new uint QtCore.QVariant.ToUInt ( )

Returns the variant as an unsigned int if the variant has type() UInt, Bool, ByteArray, Char, Double, Int, LongLong, String, or ULongLong; otherwise returns 0.

If ok is non-null: *ok is set to true if the value could be converted to an unsigned int; otherwise *ok is set to false.

Warning: If the value is convertible to a ULongLong but is too large to be represented in an unsigned int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toUInt(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also canConvert() and convert().

new uint QtCore.QVariant.ToUInt ( ref bool  ok)

Returns the variant as an unsigned int if the variant has type() UInt, Bool, ByteArray, Char, Double, Int, LongLong, String, or ULongLong; otherwise returns 0.

If ok is non-null: *ok is set to true if the value could be converted to an unsigned int; otherwise *ok is set to false.

Warning: If the value is convertible to a ULongLong but is too large to be represented in an unsigned int, the resulting arithmetic overflow will not be reflected in ok. A simple workaround is to use QString::toUInt(). Fixing this bug has been postponed to Qt 5 in order to avoid breaking existing code.

See also canConvert() and convert().

new ulong QtCore.QVariant.ToULongLong ( )

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

new ulong QtCore.QVariant.ToULongLong ( ref bool  ok)

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

new QUrl QtCore.QVariant.ToUrl ( )

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

See also canConvert() and convert().

new QVariant.Type QtCore.QVariant.type ( )

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

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

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

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

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

new string QtCore.QVariant.TypeName ( )

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.

static string QtCore.QVariant.TypeToName ( QVariant.Type  type)
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.

new int QtCore.QVariant.UserType ( )

Returns the storage type of the value stored in the variant. For non-user types, this is the same as type().

See also type().

Member Data Documentation

SmokeInvocation QtCore.QVariant.interceptor
protected

Property Documentation

virtual System.IntPtr QtCore.QVariant.SmokeObject
getset