Struct qt_core::QVariant

source ·
#[repr(C)]
pub struct QVariant { /* private fields */ }
Expand description

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

C++ class: QVariant.

C++ documentation:

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 Creating Custom Qt Types for details.

Implementations§

source§

impl QVariant

source

pub unsafe fn can_convert(&self, target_type_id: c_int) -> bool

Returns true if the variant's type can be cast to the requested type, targetTypeId. Such casting is done automatically when calling the toInt(), toBool(), ... methods.

Calls C++ function: bool QVariant::canConvert(int targetTypeId) const.

C++ documentation:

Returns true if the variant’s type can be cast to the requested type, targetTypeId. Such casting is done automatically when calling the toInt(), toBool(), … methods.

The following casts are done automatically:

TypeAutomatically Cast To
QMetaType::BoolQMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, QMetaType::ULongLong
QMetaType::QByteArrayQMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, QMetaType::ULongLong, QMetaType::QUuid
QMetaType::QCharQMetaType::Bool, QMetaType::Int, QMetaType::UInt, QMetaType::LongLong, QMetaType::ULongLong
QMetaType::QColorQMetaType::QString
QMetaType::QDateQMetaType::QDateTime, QMetaType::QString
QMetaType::QDateTimeQMetaType::QDate, QMetaType::QString, QMetaType::QTime
QMetaType::DoubleQMetaType::Bool, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, QMetaType::ULongLong
QMetaType::QFontQMetaType::QString
QMetaType::IntQMetaType::Bool, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, QMetaType::ULongLong
QMetaType::QKeySequenceQMetaType::Int, QMetaType::QString
QMetaType::QVariantListQMetaType::QStringList (if the list's items can be converted to QStrings)
QMetaType::LongLongQMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::QString, QMetaType::UInt, QMetaType::ULongLong
QMetaType::QPointQMetaType::QPointF
QMetaType::QRectQMetaType::QRectF
QMetaType::QStringQMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::QColor, QMetaType::QDate, QMetaType::QDateTime, QMetaType::Double, QMetaType::QFont, QMetaType::Int, QMetaType::QKeySequence, QMetaType::LongLong, QMetaType::QStringList, QMetaType::QTime, QMetaType::UInt, QMetaType::ULongLong, QMetaType::QUuid
QMetaType::QStringListQMetaType::QVariantList, QMetaType::QString (if the list contains exactly one item)
QMetaType::QTimeQMetaType::QString
QMetaType::UIntQMetaType::Bool, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::ULongLong
QMetaType::ULongLongQMetaType::Bool, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt
QMetaType::QUuidQMetaType::QByteArray, QMetaType::QString

A QVariant containing a pointer to a type derived from QObject will also return true for this function if a qobject_cast to the type described by targetTypeId would succeed. Note that this only works for QObject subclasses which use the Q_OBJECT macro.

A QVariant containing a sequential container will also return true for this function if the targetTypeId is QVariantList. It is possible to iterate over the contents of the container without extracting it as a (copied) QVariantList:

QList<int> intList = {7, 11, 42};

QVariant variant = QVariant::fromValue(intList); if (variant.canConvert<QVariantList>()) { QSequentialIterable iterable = variant.value<QSequentialIterable>(); // Can use foreach: foreach (const QVariant &v, iterable) { qDebug() << v; } // Can use C++11 range-for: for (const QVariant &v : iterable) { qDebug() << v; } // Can use iterators: QSequentialIterable::const_iterator it = iterable.begin(); const QSequentialIterable::const_iterator end = iterable.end(); for ( ; it != end; ++it) { qDebug() << *it; } }

This requires that the value_type of the container is itself a metatype.

Similarly, a QVariant containing a sequential container will also return true for this function the targetTypeId is QVariantHash or QVariantMap. It is possible to iterate over the contents of the container without extracting it as a (copied) QVariantHash or QVariantMap:

QHash<int, QString> mapping; mapping.insert(7, “Seven”); mapping.insert(11, “Eleven”); mapping.insert(42, “Forty-two”);

QVariant variant = QVariant::fromValue(mapping); if (variant.canConvert<QVariantHash>()) { QAssociativeIterable iterable = variant.value<QAssociativeIterable>(); // Can use foreach over the values: foreach (const QVariant &v, iterable) { qDebug() << v; } // Can use C++11 range-for over the values: for (const QVariant &v : iterable) { qDebug() << v; } // Can use iterators: QAssociativeIterable::const_iterator it = iterable.begin(); const QAssociativeIterable::const_iterator end = iterable.end(); for ( ; it != end; ++it) { qDebug() << *it; // The current value qDebug() << it.key(); qDebug() << it.value(); } }

See also convert(), QSequentialIterable, Q_DECLARE_SEQUENTIAL_CONTAINER_METATYPE(), QAssociativeIterable, and Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE().

source

pub unsafe fn clear(&self)

Convert this variant to type QMetaType::UnknownType and free up any resources used.

Calls C++ function: void QVariant::clear().

C++ documentation:

Convert this variant to type QMetaType::UnknownType and free up any resources used.

source

pub unsafe fn const_data(&self) -> *const c_void

Calls C++ function: const void* QVariant::constData() const.

source

pub unsafe fn convert(&self, target_type_id: c_int) -> bool

Casts the variant to the requested type, targetTypeId. 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.

Calls C++ function: bool QVariant::convert(int targetTypeId).

C++ documentation:

Casts the variant to the requested type, targetTypeId. 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.

A QVariant containing a pointer to a type derived from QObject will also convert and return true for this function if a qobject_cast to the type described by targetTypeId would succeed. Note that this only works for QObject subclasses which use the Q_OBJECT macro.

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

source

pub unsafe fn copy_from( &self, other: impl CastInto<Ref<QVariant>> ) -> Ref<QVariant>

Assigns the value of the variant variant to this variant.

Calls C++ function: QVariant& QVariant::operator=(const QVariant& other).

C++ documentation:

Assigns the value of the variant variant to this variant.

source

pub unsafe fn data_mut(&self) -> *mut c_void

Calls C++ function: void* QVariant::data().

source

pub unsafe fn data(&self) -> *const c_void

Calls C++ function: const void* QVariant::data() const.

source

pub unsafe fn detach(&self)

Calls C++ function: void QVariant::detach().

source

pub unsafe fn from_value( value: impl CastInto<Ref<QVariant>> ) -> CppBox<QVariant>

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

Calls C++ function: static QVariant QVariant::fromValue(const QVariant& value).

Warning: no exact match found in C++ documentation. Below is the C++ documentation for static QVariant QVariant::fromValue(const T &value):

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

Example:

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

Note: If you are working with custom types, you should use the Q_DECLARE_METATYPE() macro to register your custom type.

See also setValue() and value().

source

pub unsafe fn is_detached(&self) -> bool

Calls C++ function: bool QVariant::isDetached() const.

source

pub unsafe fn is_null(&self) -> bool

Returns true if this is a null variant, false otherwise. A variant is considered null if it contains a default constructed value or a built-in type instance that has an isNull method, in which case the result would be the same as calling isNull on the wrapped object.

Calls C++ function: bool QVariant::isNull() const.

C++ documentation:

Returns true if this is a null variant, false otherwise. A variant is considered null if it contains a default constructed value or a built-in type instance that has an isNull method, in which case the result would be the same as calling isNull on the wrapped object.

Warning: The result of the function doesn't affect == operator, which means that two values can be equal even if one of them is null and another is not.

source

pub unsafe fn is_valid(&self) -> bool

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

Calls C++ function: bool QVariant::isValid() const.

C++ documentation:

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

source

pub unsafe fn load(&self, ds: impl CastInto<Ref<QDataStream>>)

Calls C++ function: void QVariant::load(QDataStream& ds).

source

pub unsafe fn name_to_type(name: *const c_char) -> Type

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

Calls C++ function: static QVariant::Type QVariant::nameToType(const char* name).

C++ documentation:

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.

source

pub unsafe fn new() -> CppBox<QVariant>

Constructs an invalid variant.

Calls C++ function: [constructor] void QVariant::QVariant().

C++ documentation:

Constructs an invalid variant.

source

pub unsafe fn from_type(type_: Type) -> CppBox<QVariant>

Constructs a null variant of type type.

Calls C++ function: [constructor] void QVariant::QVariant(QVariant::Type type).

C++ documentation:

Constructs a null variant of type type.

source

pub unsafe fn from_int_void( type_id: c_int, copy: *const c_void ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(int typeId, const void* copy).

C++ documentation:

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

Note that you have to pass the address of the variable you want stored.

Usually, you never have to use this constructor, use QVariant::fromValue() instead to construct variants from the pointer types represented by QMetaType::VoidStar, and QMetaType::QObjectStar.

See also QVariant::fromValue() and QMetaType::Type.

source

pub unsafe fn from_int_void_uint( type_id: c_int, copy: *const c_void, flags: c_uint ) -> CppBox<QVariant>

Calls C++ function: [constructor] void QVariant::QVariant(int typeId, const void* copy, unsigned int flags).

source

pub unsafe fn from_q_data_stream( s: impl CastInto<Ref<QDataStream>> ) -> CppBox<QVariant>

Reads the variant from the data stream, s.

Calls C++ function: [constructor] void QVariant::QVariant(QDataStream& s).

C++ documentation:

Reads the variant from the data stream, s.

source

pub unsafe fn from_int(i: c_int) -> CppBox<QVariant>

Constructs a new variant with an integer value, val.

Calls C++ function: [constructor] void QVariant::QVariant(int i).

C++ documentation:

Constructs a new variant with an integer value, val.

source

pub unsafe fn from_uint(ui: c_uint) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(unsigned int ui).

C++ documentation:

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

source

pub unsafe fn from_i64(ll: i64) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(qlonglong ll).

C++ documentation:

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

source

pub unsafe fn from_u64(ull: u64) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(qulonglong ull).

C++ documentation:

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

source

pub unsafe fn from_bool(b: bool) -> CppBox<QVariant>

Constructs a new variant with a boolean value, val.

Calls C++ function: [constructor] void QVariant::QVariant(bool b).

C++ documentation:

Constructs a new variant with a boolean value, val.

source

pub unsafe fn from_double(d: c_double) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(double d).

C++ documentation:

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

source

pub unsafe fn from_float(f: c_float) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(float f).

C++ documentation:

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

This function was introduced in Qt 4.6.

source

pub unsafe fn from_char(str: *const c_char) -> CppBox<QVariant>

Constructs a new variant with a string value of val. The variant creates a deep copy of val into a QString assuming UTF-8 encoding on the input val.

Calls C++ function: [constructor] void QVariant::QVariant(const char* str).

C++ documentation:

Constructs a new variant with a string value of val. The variant creates a deep copy of val into a QString assuming UTF-8 encoding on the input val.

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

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

source

pub unsafe fn from_q_byte_array( bytearray: impl CastInto<Ref<QByteArray>> ) -> CppBox<QVariant>

Constructs a new variant with a bytearray value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QByteArray& bytearray).

C++ documentation:

Constructs a new variant with a bytearray value, val.

source

pub unsafe fn from_q_bit_array( bitarray: impl CastInto<Ref<QBitArray>> ) -> CppBox<QVariant>

Constructs a new variant with a bitarray value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QBitArray& bitarray).

C++ documentation:

Constructs a new variant with a bitarray value, val.

source

pub unsafe fn from_q_string( string: impl CastInto<Ref<QString>> ) -> CppBox<QVariant>

Constructs a new variant with a string value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QString& string).

C++ documentation:

Constructs a new variant with a string value, val.

source

pub unsafe fn from_q_latin1_string( string: impl CastInto<Ref<QLatin1String>> ) -> CppBox<QVariant>

Constructs a new variant with a string value, val.

Calls C++ function: [constructor] void QVariant::QVariant(QLatin1String string).

C++ documentation:

Constructs a new variant with a string value, val.

source

pub unsafe fn from_q_string_list( stringlist: impl CastInto<Ref<QStringList>> ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QStringList& stringlist).

C++ documentation:

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

source

pub unsafe fn from_q_char(qchar: impl CastInto<Ref<QChar>>) -> CppBox<QVariant>

Constructs a new variant with a char value, c.

Calls C++ function: [constructor] void QVariant::QVariant(QChar qchar).

C++ documentation:

Constructs a new variant with a char value, c.

source

pub unsafe fn from_q_date(date: impl CastInto<Ref<QDate>>) -> CppBox<QVariant>

Constructs a new variant with a date value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QDate& date).

C++ documentation:

Constructs a new variant with a date value, val.

source

pub unsafe fn from_q_time(time: impl CastInto<Ref<QTime>>) -> CppBox<QVariant>

Constructs a new variant with a time value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QTime& time).

C++ documentation:

Constructs a new variant with a time value, val.

source

pub unsafe fn from_q_date_time( datetime: impl CastInto<Ref<QDateTime>> ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QDateTime& datetime).

C++ documentation:

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

source

pub unsafe fn from_q_list_of_q_variant( list: impl CastInto<Ref<QListOfQVariant>> ) -> CppBox<QVariant>

Constructs a new variant with a list value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QList<QVariant>& list).

C++ documentation:

Constructs a new variant with a list value, val.

source

pub unsafe fn from_q_map_of_q_string_q_variant( map: impl CastInto<Ref<QMapOfQStringQVariant>> ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QMap<QString, QVariant>& map).

C++ documentation:

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

source

pub unsafe fn from_q_hash_of_q_string_q_variant( hash: impl CastInto<Ref<QHashOfQStringQVariant>> ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QHash<QString, QVariant>& hash).

C++ documentation:

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

source

pub unsafe fn from_q_size(size: impl CastInto<Ref<QSize>>) -> CppBox<QVariant>

Constructs a new variant with a size value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QSize& size).

C++ documentation:

Constructs a new variant with a size value of val.

source

pub unsafe fn from_q_size_f( size: impl CastInto<Ref<QSizeF>> ) -> CppBox<QVariant>

Constructs a new variant with a size value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QSizeF& size).

C++ documentation:

Constructs a new variant with a size value of val.

source

pub unsafe fn from_q_point(pt: impl CastInto<Ref<QPoint>>) -> CppBox<QVariant>

Constructs a new variant with a point value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QPoint& pt).

C++ documentation:

Constructs a new variant with a point value of val.

source

pub unsafe fn from_q_point_f( pt: impl CastInto<Ref<QPointF>> ) -> CppBox<QVariant>

Constructs a new variant with a point value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QPointF& pt).

C++ documentation:

Constructs a new variant with a point value of val.

source

pub unsafe fn from_q_line(line: impl CastInto<Ref<QLine>>) -> CppBox<QVariant>

Constructs a new variant with a line value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QLine& line).

C++ documentation:

Constructs a new variant with a line value of val.

source

pub unsafe fn from_q_line_f( line: impl CastInto<Ref<QLineF>> ) -> CppBox<QVariant>

Constructs a new variant with a line value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QLineF& line).

C++ documentation:

Constructs a new variant with a line value of val.

source

pub unsafe fn from_q_rect(rect: impl CastInto<Ref<QRect>>) -> CppBox<QVariant>

Constructs a new variant with a rect value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QRect& rect).

C++ documentation:

Constructs a new variant with a rect value of val.

source

pub unsafe fn from_q_rect_f( rect: impl CastInto<Ref<QRectF>> ) -> CppBox<QVariant>

Constructs a new variant with a rect value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QRectF& rect).

C++ documentation:

Constructs a new variant with a rect value of val.

source

pub unsafe fn from_q_locale( locale: impl CastInto<Ref<QLocale>> ) -> CppBox<QVariant>

Constructs a new variant with a locale value, l.

Calls C++ function: [constructor] void QVariant::QVariant(const QLocale& locale).

C++ documentation:

Constructs a new variant with a locale value, l.

source

pub unsafe fn from_q_reg_exp( reg_exp: impl CastInto<Ref<QRegExp>> ) -> CppBox<QVariant>

Constructs a new variant with the regexp value regExp.

Calls C++ function: [constructor] void QVariant::QVariant(const QRegExp& regExp).

C++ documentation:

Constructs a new variant with the regexp value regExp.

source

pub unsafe fn from_q_regular_expression( re: impl CastInto<Ref<QRegularExpression>> ) -> CppBox<QVariant>

Constructs a new variant with the regular expression value re.

Calls C++ function: [constructor] void QVariant::QVariant(const QRegularExpression& re).

C++ documentation:

Constructs a new variant with the regular expression value re.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_url(url: impl CastInto<Ref<QUrl>>) -> CppBox<QVariant>

Constructs a new variant with a url value of val.

Calls C++ function: [constructor] void QVariant::QVariant(const QUrl& url).

C++ documentation:

Constructs a new variant with a url value of val.

source

pub unsafe fn from_q_easing_curve( easing: impl CastInto<Ref<QEasingCurve>> ) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QEasingCurve& easing).

C++ documentation:

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

This function was introduced in Qt 4.7.

source

pub unsafe fn from_q_uuid(uuid: impl CastInto<Ref<QUuid>>) -> CppBox<QVariant>

Constructs a new variant with an uuid value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QUuid& uuid).

C++ documentation:

Constructs a new variant with an uuid value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_model_index( model_index: impl CastInto<Ref<QModelIndex>> ) -> CppBox<QVariant>

Constructs a new variant with a QModelIndex value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QModelIndex& modelIndex).

C++ documentation:

Constructs a new variant with a QModelIndex value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_persistent_model_index( model_index: impl CastInto<Ref<QPersistentModelIndex>> ) -> CppBox<QVariant>

Constructs a new variant with a QPersistentModelIndex value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QPersistentModelIndex& modelIndex).

C++ documentation:

Constructs a new variant with a QPersistentModelIndex value, val.

This function was introduced in Qt 5.5.

source

pub unsafe fn from_q_json_value( json_value: impl CastInto<Ref<QJsonValue>> ) -> CppBox<QVariant>

Constructs a new variant with a json value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QJsonValue& jsonValue).

C++ documentation:

Constructs a new variant with a json value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_json_object( json_object: impl CastInto<Ref<QJsonObject>> ) -> CppBox<QVariant>

Constructs a new variant with a json object value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QJsonObject& jsonObject).

C++ documentation:

Constructs a new variant with a json object value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_json_array( json_array: impl CastInto<Ref<QJsonArray>> ) -> CppBox<QVariant>

Constructs a new variant with a json array value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QJsonArray& jsonArray).

C++ documentation:

Constructs a new variant with a json array value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn from_q_json_document( json_document: impl CastInto<Ref<QJsonDocument>> ) -> CppBox<QVariant>

Constructs a new variant with a json document value, val.

Calls C++ function: [constructor] void QVariant::QVariant(const QJsonDocument& jsonDocument).

C++ documentation:

Constructs a new variant with a json document value, val.

This function was introduced in Qt 5.0.

source

pub unsafe fn new_copy(other: impl CastInto<Ref<QVariant>>) -> CppBox<QVariant>

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

Calls C++ function: [constructor] void QVariant::QVariant(const QVariant& other).

C++ documentation:

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

source

pub unsafe fn save(&self, ds: impl CastInto<Ref<QDataStream>>)

Calls C++ function: void QVariant::save(QDataStream& ds) const.

source

pub unsafe fn set_value(&self, avalue: impl CastInto<Ref<QVariant>>)

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.

Calls C++ function: void QVariant::setValue(const QVariant& avalue).

Warning: no exact match found in C++ documentation. Below is the C++ documentation for void QVariant::setValue(const T &value):

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

See also value(), fromValue(), and canConvert().

source

pub unsafe fn swap(&self, other: impl CastInto<Ref<QVariant>>)

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

Calls C++ function: void QVariant::swap(QVariant& other).

C++ documentation:

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

This function was introduced in Qt 4.8.

source

pub unsafe fn to_bit_array(&self) -> CppBox<QBitArray>

Returns the variant as a QBitArray if the variant has userType() QMetaType::QBitArray; otherwise returns an empty bit array.

Calls C++ function: QBitArray QVariant::toBitArray() const.

C++ documentation:

Returns the variant as a QBitArray if the variant has userType() QMetaType::QBitArray; otherwise returns an empty bit array.

See also canConvert() and convert().

source

pub unsafe fn to_bool(&self) -> bool

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

Calls C++ function: bool QVariant::toBool() const.

C++ documentation:

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

Returns true if the variant has userType() QMetaType::Bool, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::UInt, or QMetaType::ULongLong and the value is non-zero, or if the variant has type QMetaType::QString or QMetaType::QByteArray and its lower-case content is not one of the following: empty, "0" or "false"; otherwise returns false.

See also canConvert() and convert().

source

pub unsafe fn to_byte_array(&self) -> CppBox<QByteArray>

Returns the variant as a QByteArray if the variant has userType() QMetaType::QByteArray or QMetaType::QString (converted using QString::fromUtf8()); otherwise returns an empty byte array.

Calls C++ function: QByteArray QVariant::toByteArray() const.

C++ documentation:

Returns the variant as a QByteArray if the variant has userType() QMetaType::QByteArray or QMetaType::QString (converted using QString::fromUtf8()); otherwise returns an empty byte array.

See also canConvert() and convert().

source

pub unsafe fn to_char(&self) -> CppBox<QChar>

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

Calls C++ function: QChar QVariant::toChar() const.

C++ documentation:

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

See also canConvert() and convert().

source

pub unsafe fn to_date(&self) -> CppBox<QDate>

Returns the variant as a QDate if the variant has userType() QMetaType::QDate, QMetaType::QDateTime, or QMetaType::QString; otherwise returns an invalid date.

Calls C++ function: QDate QVariant::toDate() const.

C++ documentation:

Returns the variant as a QDate if the variant has userType() QMetaType::QDate, QMetaType::QDateTime, or QMetaType::QString; otherwise returns an invalid date.

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

See also canConvert() and convert().

source

pub unsafe fn to_date_time(&self) -> CppBox<QDateTime>

Returns the variant as a QDateTime if the variant has userType() QMetaType::QDateTime, QMetaType::QDate, or QMetaType::QString; otherwise returns an invalid date/time.

Calls C++ function: QDateTime QVariant::toDateTime() const.

C++ documentation:

Returns the variant as a QDateTime if the variant has userType() QMetaType::QDateTime, QMetaType::QDate, or QMetaType::QString; otherwise returns an invalid date/time.

If the type() is QMetaType::QString, 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().

source

pub unsafe fn to_double_1a(&self, ok: *mut bool) -> c_double

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

Calls C++ function: double QVariant::toDouble(bool* ok = …) const.

C++ documentation:

Returns the variant as a double if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_double_0a(&self) -> c_double

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

Calls C++ function: double QVariant::toDouble() const.

C++ documentation:

Returns the variant as a double if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_easing_curve(&self) -> CppBox<QEasingCurve>

Returns the variant as a QEasingCurve if the variant has userType() QMetaType::QEasingCurve; otherwise returns a default easing curve.

Calls C++ function: QEasingCurve QVariant::toEasingCurve() const.

C++ documentation:

Returns the variant as a QEasingCurve if the variant has userType() QMetaType::QEasingCurve; otherwise returns a default easing curve.

This function was introduced in Qt 4.7.

See also canConvert() and convert().

source

pub unsafe fn to_float_1a(&self, ok: *mut bool) -> c_float

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

Calls C++ function: float QVariant::toFloat(bool* ok = …) const.

C++ documentation:

Returns the variant as a float if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_float_0a(&self) -> c_float

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

Calls C++ function: float QVariant::toFloat() const.

C++ documentation:

Returns the variant as a float if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_hash(&self) -> CppBox<QHashOfQStringQVariant>

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

Calls C++ function: QHash<QString, QVariant> QVariant::toHash() const.

C++ documentation:

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

See also canConvert() and convert().

source

pub unsafe fn to_int_1a(&self, ok: *mut bool) -> c_int

Returns the variant as an int if the variant has userType() QMetaType::Int, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: int QVariant::toInt(bool* ok = …) const.

C++ documentation:

Returns the variant as an int if the variant has userType() QMetaType::Int, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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 QMetaType::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().

See also canConvert() and convert().

source

pub unsafe fn to_int_0a(&self) -> c_int

Returns the variant as an int if the variant has userType() QMetaType::Int, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: int QVariant::toInt() const.

C++ documentation:

Returns the variant as an int if the variant has userType() QMetaType::Int, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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 QMetaType::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().

See also canConvert() and convert().

source

pub unsafe fn to_json_array(&self) -> CppBox<QJsonArray>

Returns the variant as a QJsonArray if the variant has userType() QJsonArray; otherwise returns a default constructed QJsonArray.

Calls C++ function: QJsonArray QVariant::toJsonArray() const.

C++ documentation:

Returns the variant as a QJsonArray if the variant has userType() QJsonArray; otherwise returns a default constructed QJsonArray.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn to_json_document(&self) -> CppBox<QJsonDocument>

Returns the variant as a QJsonDocument if the variant has userType() QJsonDocument; otherwise returns a default constructed QJsonDocument.

Calls C++ function: QJsonDocument QVariant::toJsonDocument() const.

C++ documentation:

Returns the variant as a QJsonDocument if the variant has userType() QJsonDocument; otherwise returns a default constructed QJsonDocument.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn to_json_object(&self) -> CppBox<QJsonObject>

Returns the variant as a QJsonObject if the variant has userType() QJsonObject; otherwise returns a default constructed QJsonObject.

Calls C++ function: QJsonObject QVariant::toJsonObject() const.

C++ documentation:

Returns the variant as a QJsonObject if the variant has userType() QJsonObject; otherwise returns a default constructed QJsonObject.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn to_json_value(&self) -> CppBox<QJsonValue>

Returns the variant as a QJsonValue if the variant has userType() QJsonValue; otherwise returns a default constructed QJsonValue.

Calls C++ function: QJsonValue QVariant::toJsonValue() const.

C++ documentation:

Returns the variant as a QJsonValue if the variant has userType() QJsonValue; otherwise returns a default constructed QJsonValue.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn to_line(&self) -> CppBox<QLine>

Returns the variant as a QLine if the variant has userType() QMetaType::QLine; otherwise returns an invalid QLine.

Calls C++ function: QLine QVariant::toLine() const.

C++ documentation:

Returns the variant as a QLine if the variant has userType() QMetaType::QLine; otherwise returns an invalid QLine.

See also canConvert() and convert().

source

pub unsafe fn to_line_f(&self) -> CppBox<QLineF>

Returns the variant as a QLineF if the variant has userType() QMetaType::QLineF; otherwise returns an invalid QLineF.

Calls C++ function: QLineF QVariant::toLineF() const.

C++ documentation:

Returns the variant as a QLineF if the variant has userType() QMetaType::QLineF; otherwise returns an invalid QLineF.

See also canConvert() and convert().

source

pub unsafe fn to_list(&self) -> CppBox<QListOfQVariant>

Returns the variant as a QVariantList if the variant has userType() QMetaType::QVariantList or QMetaType::QStringList; otherwise returns an empty list.

Calls C++ function: QList<QVariant> QVariant::toList() const.

C++ documentation:

Returns the variant as a QVariantList if the variant has userType() QMetaType::QVariantList or QMetaType::QStringList; otherwise returns an empty list.

See also canConvert() and convert().

source

pub unsafe fn to_locale(&self) -> CppBox<QLocale>

Returns the variant as a QLocale if the variant has userType() QMetaType::QLocale; otherwise returns an invalid QLocale.

Calls C++ function: QLocale QVariant::toLocale() const.

C++ documentation:

Returns the variant as a QLocale if the variant has userType() QMetaType::QLocale; otherwise returns an invalid QLocale.

See also canConvert() and convert().

source

pub unsafe fn to_long_long_1a(&self, ok: *mut bool) -> i64

Returns the variant as a long long int if the variant has userType() QMetaType::LongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::QString, QMetaType::UInt, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: qlonglong QVariant::toLongLong(bool* ok = …) const.

C++ documentation:

Returns the variant as a long long int if the variant has userType() QMetaType::LongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_long_long_0a(&self) -> i64

Returns the variant as a long long int if the variant has userType() QMetaType::LongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::QString, QMetaType::UInt, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: qlonglong QVariant::toLongLong() const.

C++ documentation:

Returns the variant as a long long int if the variant has userType() QMetaType::LongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_map(&self) -> CppBox<QMapOfQStringQVariant>

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

Calls C++ function: QMap<QString, QVariant> QVariant::toMap() const.

C++ documentation:

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

See also canConvert() and convert().

source

pub unsafe fn to_model_index(&self) -> CppBox<QModelIndex>

Returns the variant as a QModelIndex if the variant has userType() QModelIndex; otherwise returns a default constructed QModelIndex.

Calls C++ function: QModelIndex QVariant::toModelIndex() const.

C++ documentation:

Returns the variant as a QModelIndex if the variant has userType() QModelIndex; otherwise returns a default constructed QModelIndex.

This function was introduced in Qt 5.0.

See also canConvert(), convert(), and toPersistentModelIndex().

source

pub unsafe fn to_persistent_model_index(&self) -> CppBox<QPersistentModelIndex>

Returns the variant as a QPersistentModelIndex if the variant has userType() QPersistentModelIndex; otherwise returns a default constructed QPersistentModelIndex.

Calls C++ function: QPersistentModelIndex QVariant::toPersistentModelIndex() const.

C++ documentation:

Returns the variant as a QPersistentModelIndex if the variant has userType() QPersistentModelIndex; otherwise returns a default constructed QPersistentModelIndex.

This function was introduced in Qt 5.5.

See also canConvert(), convert(), and toModelIndex().

source

pub unsafe fn to_point(&self) -> CppBox<QPoint>

Returns the variant as a QPoint if the variant has userType() QMetaType::QPoint or QMetaType::QPointF; otherwise returns a null QPoint.

Calls C++ function: QPoint QVariant::toPoint() const.

C++ documentation:

Returns the variant as a QPoint if the variant has userType() QMetaType::QPoint or QMetaType::QPointF; otherwise returns a null QPoint.

See also canConvert() and convert().

source

pub unsafe fn to_point_f(&self) -> CppBox<QPointF>

Returns the variant as a QPointF if the variant has userType() QMetaType::QPoint or QMetaType::QPointF; otherwise returns a null QPointF.

Calls C++ function: QPointF QVariant::toPointF() const.

C++ documentation:

Returns the variant as a QPointF if the variant has userType() QMetaType::QPoint or QMetaType::QPointF; otherwise returns a null QPointF.

See also canConvert() and convert().

source

pub unsafe fn to_real_1a(&self, ok: *mut bool) -> c_double

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

Calls C++ function: double QVariant::toReal(bool* ok = …) const.

C++ documentation:

Returns the variant as a qreal if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_real_0a(&self) -> c_double

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

Calls C++ function: double QVariant::toReal() const.

C++ documentation:

Returns the variant as a qreal if the variant has userType() QMetaType::Double, QMetaType::Float, QMetaType::Bool, QMetaType::QByteArray, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, QMetaType::UInt, or QMetaType::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().

source

pub unsafe fn to_rect(&self) -> CppBox<QRect>

Returns the variant as a QRect if the variant has userType() QMetaType::QRect; otherwise returns an invalid QRect.

Calls C++ function: QRect QVariant::toRect() const.

C++ documentation:

Returns the variant as a QRect if the variant has userType() QMetaType::QRect; otherwise returns an invalid QRect.

See also canConvert() and convert().

source

pub unsafe fn to_rect_f(&self) -> CppBox<QRectF>

Returns the variant as a QRectF if the variant has userType() QMetaType::QRect or QMetaType::QRectF; otherwise returns an invalid QRectF.

Calls C++ function: QRectF QVariant::toRectF() const.

C++ documentation:

Returns the variant as a QRectF if the variant has userType() QMetaType::QRect or QMetaType::QRectF; otherwise returns an invalid QRectF.

See also canConvert() and convert().

source

pub unsafe fn to_reg_exp(&self) -> CppBox<QRegExp>

Returns the variant as a QRegExp if the variant has userType() QMetaType::QRegExp; otherwise returns an empty QRegExp.

Calls C++ function: QRegExp QVariant::toRegExp() const.

C++ documentation:

Returns the variant as a QRegExp if the variant has userType() QMetaType::QRegExp; otherwise returns an empty QRegExp.

This function was introduced in Qt 4.1.

See also canConvert() and convert().

source

pub unsafe fn to_regular_expression(&self) -> CppBox<QRegularExpression>

Returns the variant as a QRegularExpression if the variant has userType() QRegularExpression; otherwise returns an empty QRegularExpression.

Calls C++ function: QRegularExpression QVariant::toRegularExpression() const.

C++ documentation:

Returns the variant as a QRegularExpression if the variant has userType() QRegularExpression; otherwise returns an empty QRegularExpression.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn to_size(&self) -> CppBox<QSize>

Returns the variant as a QSize if the variant has userType() QMetaType::QSize; otherwise returns an invalid QSize.

Calls C++ function: QSize QVariant::toSize() const.

C++ documentation:

Returns the variant as a QSize if the variant has userType() QMetaType::QSize; otherwise returns an invalid QSize.

See also canConvert() and convert().

source

pub unsafe fn to_size_f(&self) -> CppBox<QSizeF>

Returns the variant as a QSizeF if the variant has userType() QMetaType::QSizeF; otherwise returns an invalid QSizeF.

Calls C++ function: QSizeF QVariant::toSizeF() const.

C++ documentation:

Returns the variant as a QSizeF if the variant has userType() QMetaType::QSizeF; otherwise returns an invalid QSizeF.

See also canConvert() and convert().

source

pub unsafe fn to_string(&self) -> CppBox<QString>

source

pub unsafe fn to_string_list(&self) -> CppBox<QStringList>

Returns the variant as a QStringList if the variant has userType() QMetaType::QStringList, QMetaType::QString, or QMetaType::QVariantList of a type that can be converted to QString; otherwise returns an empty list.

Calls C++ function: QStringList QVariant::toStringList() const.

C++ documentation:

Returns the variant as a QStringList if the variant has userType() QMetaType::QStringList, QMetaType::QString, or QMetaType::QVariantList of a type that can be converted to QString; otherwise returns an empty list.

See also canConvert() and convert().

source

pub unsafe fn to_time(&self) -> CppBox<QTime>

Returns the variant as a QTime if the variant has userType() QMetaType::QTime, QMetaType::QDateTime, or QMetaType::QString; otherwise returns an invalid time.

Calls C++ function: QTime QVariant::toTime() const.

C++ documentation:

Returns the variant as a QTime if the variant has userType() QMetaType::QTime, QMetaType::QDateTime, or QMetaType::QString; otherwise returns an invalid time.

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

See also canConvert() and convert().

source

pub unsafe fn to_u_int_1a(&self, ok: *mut bool) -> c_uint

Returns the variant as an unsigned int if the variant has userType() QMetaType::UInt, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: unsigned int QVariant::toUInt(bool* ok = …) const.

C++ documentation:

Returns the variant as an unsigned int if the variant has userType() QMetaType::UInt, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::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 QMetaType::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().

See also canConvert() and convert().

source

pub unsafe fn to_u_int_0a(&self) -> c_uint

Returns the variant as an unsigned int if the variant has userType() QMetaType::UInt, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::ULongLong; otherwise returns 0.

Calls C++ function: unsigned int QVariant::toUInt() const.

C++ documentation:

Returns the variant as an unsigned int if the variant has userType() QMetaType::UInt, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::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 QMetaType::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().

See also canConvert() and convert().

source

pub unsafe fn to_u_long_long_1a(&self, ok: *mut bool) -> u64

Returns the variant as an unsigned long long int if the variant has type() QMetaType::ULongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::UInt; otherwise returns 0.

Calls C++ function: qulonglong QVariant::toULongLong(bool* ok = …) const.

C++ documentation:

Returns the variant as an unsigned long long int if the variant has type() QMetaType::ULongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::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().

source

pub unsafe fn to_u_long_long_0a(&self) -> u64

Returns the variant as an unsigned long long int if the variant has type() QMetaType::ULongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::UInt; otherwise returns 0.

Calls C++ function: qulonglong QVariant::toULongLong() const.

C++ documentation:

Returns the variant as an unsigned long long int if the variant has type() QMetaType::ULongLong, QMetaType::Bool, QMetaType::QByteArray, QMetaType::QChar, QMetaType::Double, QMetaType::Int, QMetaType::LongLong, QMetaType::QString, or QMetaType::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().

source

pub unsafe fn to_url(&self) -> CppBox<QUrl>

Returns the variant as a QUrl if the variant has userType() QMetaType::QUrl; otherwise returns an invalid QUrl.

Calls C++ function: QUrl QVariant::toUrl() const.

C++ documentation:

Returns the variant as a QUrl if the variant has userType() QMetaType::QUrl; otherwise returns an invalid QUrl.

See also canConvert() and convert().

source

pub unsafe fn to_uuid(&self) -> CppBox<QUuid>

Returns the variant as a QUuid if the variant has type() QMetaType::QUuid, QMetaType::QByteArray or QMetaType::QString; otherwise returns a default-constructed QUuid.

Calls C++ function: QUuid QVariant::toUuid() const.

C++ documentation:

Returns the variant as a QUuid if the variant has type() QMetaType::QUuid, QMetaType::QByteArray or QMetaType::QString; otherwise returns a default-constructed QUuid.

This function was introduced in Qt 5.0.

See also canConvert() and convert().

source

pub unsafe fn type_(&self) -> 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.

Calls C++ function: QVariant::Type QVariant::type() const.

C++ documentation:

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

source

pub unsafe fn type_name(&self) -> *const c_char

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.

Calls C++ function: const char* QVariant::typeName() const.

C++ documentation:

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.

source

pub unsafe fn type_to_name(type_id: c_int) -> *const c_char

Converts the int representation of the storage type, typeId, to its string representation.

Calls C++ function: static const char* QVariant::typeToName(int typeId).

C++ documentation:

Converts the int representation of the storage type, typeId, to its string representation.

Returns a null pointer if the type is QMetaType::UnknownType or doesn't exist.

source

pub unsafe fn user_type(&self) -> c_int

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

Calls C++ function: int QVariant::userType() const.

C++ documentation:

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

See also type().

Trait Implementations§

source§

impl CppDeletable for QVariant

source§

unsafe fn delete(&self)

Destroys the QVariant and the contained object.

Calls C++ function: [destructor] void QVariant::~QVariant().

C++ documentation:

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

source§

impl Data for QVariant

source§

unsafe fn data(&self) -> *const c_void

Calls C++ function: const void* QVariant::data() const.

§

type Output = *const c_void

Return type of data() function.
source§

impl DataMut for QVariant

source§

unsafe fn data_mut(&self) -> *mut c_void

Calls C++ function: void* QVariant::data().

§

type Output = *mut c_void

Return type of data_mut() function.
source§

impl Ge<Ref<QVariant>> for QVariant

source§

unsafe fn ge(&self, v: &Ref<QVariant>) -> bool

Compares this QVariant with v and returns true if this is larger or equal than v.

Calls C++ function: bool QVariant::operator>=(const QVariant& v) const.

C++ documentation:

Compares this QVariant with v and returns true if this is larger or equal than v.

Note: Comparability might not be available for the type stored in this QVariant or in v.

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

source§

impl Gt<Ref<QVariant>> for QVariant

source§

unsafe fn gt(&self, v: &Ref<QVariant>) -> bool

Compares this QVariant with v and returns true if this is larger than v.

Calls C++ function: bool QVariant::operator>(const QVariant& v) const.

C++ documentation:

Compares this QVariant with v and returns true if this is larger than v.

Note: Comparability might not be available for the type stored in this QVariant or in v.

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

source§

impl Le<Ref<QVariant>> for QVariant

source§

unsafe fn le(&self, v: &Ref<QVariant>) -> bool

Compares this QVariant with v and returns true if this is less or equal than v.

Calls C++ function: bool QVariant::operator<=(const QVariant& v) const.

C++ documentation:

Compares this QVariant with v and returns true if this is less or equal than v.

Note: Comparability might not be available for the type stored in this QVariant or in v.

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

source§

impl Lt<Ref<QVariant>> for QVariant

source§

unsafe fn lt(&self, v: &Ref<QVariant>) -> bool

Compares this QVariant with v and returns true if this is less than v.

Calls C++ function: bool QVariant::operator<(const QVariant& v) const.

C++ documentation:

Compares this QVariant with v and returns true if this is less than v.

Note: Comparability might not be availabe for the type stored in this QVariant or in v.

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

source§

impl PartialEq<Ref<QVariant>> for QVariant

source§

fn eq(&self, v: &Ref<QVariant>) -> bool

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

Calls C++ function: bool QVariant::operator==(const QVariant& v) const.

C++ documentation:

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

QVariant uses the equality operator of the type() it contains to check for equality. QVariant will try to convert() v if its type is not the same as this variant's type. See canConvert() for a list of possible conversions.

Warning: To make this function work with a custom type registered with qRegisterMetaType(), its comparison operator must be registered using QMetaType::registerComparators().

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.