Obsolete Members for QVariant

The following members of class QVariant are deprecated. They are provided to keep old source code working. We strongly advise against using them in new code.

Public Types

(deprecated) enum Type { Invalid, BitArray, Bitmap, Bool, Brush, …, UserType }

Public Functions

(deprecated in 6.0) QVariant(QVariant::Type type)
(deprecated in 6.0) bool canConvert(int targetTypeId) const
(deprecated in 6.0) bool convert(int targetTypeId)
(deprecated in 6.0) QVariant::Type type() const

Static Public Members

(deprecated in 6.0) QVariant::Type nameToType(const char *name)
(deprecated in 6.0) const char *typeToName(int typeId)

Related Non-Members

(deprecated in 6.0) QDataStream &operator<<(QDataStream &s, const QVariant::Type p)
(deprecated in 6.0) QDataStream &operator>>(QDataStream &s, QVariant::Type &p)

Member Type Documentation

[deprecated] enum QVariant::Type

This enum is deprecated. We strongly advise against using it in new code.

Use QMetaType::Type instead.

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

ConstantValueDescription
QVariant::InvalidQMetaType::UnknownTypeno type
QVariant::BitArrayQMetaType::QBitArraya QBitArray
QVariant::BitmapQMetaType::QBitmapa QBitmap
QVariant::BoolQMetaType::Boola bool
QVariant::BrushQMetaType::QBrusha QBrush
QVariant::ByteArrayQMetaType::QByteArraya QByteArray
QVariant::CharQMetaType::QChara QChar
QVariant::ColorQMetaType::QColora QColor
QVariant::CursorQMetaType::QCursora QCursor
QVariant::DateQMetaType::QDatea QDate
QVariant::DateTimeQMetaType::QDateTimea QDateTime
QVariant::DoubleQMetaType::Doublea double
QVariant::EasingCurveQMetaType::QEasingCurvea QEasingCurve
QVariant::UuidQMetaType::QUuida QUuid
QVariant::ModelIndexQMetaType::QModelIndexa QModelIndex
QVariant::PersistentModelIndex (since Qt 5.5)QMetaType::QPersistentModelIndexa QPersistentModelIndex
QVariant::FontQMetaType::QFonta QFont
QVariant::HashQMetaType::QVariantHasha QVariantHash
QVariant::IconQMetaType::QIcona QIcon
QVariant::ImageQMetaType::QImagea QImage
QVariant::IntQMetaType::Intan int
QVariant::KeySequenceQMetaType::QKeySequencea QKeySequence
QVariant::LineQMetaType::QLinea QLine
QVariant::LineFQMetaType::QLineFa QLineF
QVariant::ListQMetaType::QVariantLista QVariantList
QVariant::LocaleQMetaType::QLocalea QLocale
QVariant::LongLongQMetaType::LongLonga qlonglong
QVariant::MapQMetaType::QVariantMapa QVariantMap
QVariant::TransformQMetaType::QTransforma QTransform
QVariant::Matrix4x4QMetaType::QMatrix4x4a QMatrix4x4
QVariant::PaletteQMetaType::QPalettea QPalette
QVariant::PenQMetaType::QPena QPen
QVariant::PixmapQMetaType::QPixmapa QPixmap
QVariant::PointQMetaType::QPointa QPoint
QVariant::PointFQMetaType::QPointFa QPointF
QVariant::PolygonQMetaType::QPolygona QPolygon
QVariant::PolygonFQMetaType::QPolygonFa QPolygonF
QVariant::QuaternionQMetaType::QQuaterniona QQuaternion
QVariant::RectQMetaType::QRecta QRect
QVariant::RectFQMetaType::QRectFa QRectF
QVariant::RegularExpressionQMetaType::QRegularExpressiona QRegularExpression
QVariant::RegionQMetaType::QRegiona QRegion
QVariant::SizeQMetaType::QSizea QSize
QVariant::SizeFQMetaType::QSizeFa QSizeF
QVariant::SizePolicyQMetaType::QSizePolicya QSizePolicy
QVariant::StringQMetaType::QStringa QString
QVariant::StringListQMetaType::QStringLista QStringList
QVariant::TextFormatQMetaType::QTextFormata QTextFormat
QVariant::TextLengthQMetaType::QTextLengtha QTextLength
QVariant::TimeQMetaType::QTimea QTime
QVariant::UIntQMetaType::UInta uint
QVariant::ULongLongQMetaType::ULongLonga qulonglong
QVariant::UrlQMetaType::QUrla QUrl
QVariant::Vector2DQMetaType::QVector2Da QVector2D
QVariant::Vector3DQMetaType::QVector3Da QVector3D
QVariant::Vector4DQMetaType::QVector4Da QVector4D
QVariant::UserTypeQMetaType::UserBase value for user-defined types.

Member Function Documentation

[explicit, deprecated in 6.0] QVariant::QVariant(QVariant::Type type)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Use the constructor taking a QMetaType instead.

Constructs an uninitialized variant of type type. This will create a variant in a special null state that if accessed will return a default constructed value of the type.

See also isNull().

[deprecated in 6.0] bool QVariant::canConvert(int targetTypeId) const

This function is deprecated since 6.0. We strongly advise against using it in new code.

This is an overloaded function.

Use canConvert(QMetaType(targetTypeId)) instead.

See also QMetaType::canConvert().

[deprecated in 6.0] bool QVariant::convert(int targetTypeId)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Use convert(QMetaType(targetTypeId)) instead.

Casts the variant to the requested type, targetTypeId. If the cast cannot be done, the variant is still changed to the requested type, but is left in a cleared null state similar to that constructed by QVariant(Type).

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.

Note: converting QVariants that are null due to not being initialized or having failed a previous conversion will always fail, changing the type, remaining null, and returning false.

See also canConvert() and clear().

[static, deprecated in 6.0] QVariant::Type QVariant::nameToType(const char *name)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Use QMetaType::fromName(name).id() instead

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.

[deprecated in 6.0] QVariant::Type QVariant::type() const

This function is deprecated since 6.0. We strongly advise against using it in new code.

Use typeId() or metaType() instead.

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

See also userType() and metaType().

[static, deprecated in 6.0] const char *QVariant::typeToName(int typeId)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Use QMetaType(typeId).name() instead.

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

Returns nullptr if the type is QMetaType::UnknownType or doesn't exist.

Related Non-Members

[deprecated in 6.0] QDataStream &operator<<(QDataStream &s, const QVariant::Type p)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Stream QMetaType::Type instead.

Writes a variant type p to the stream s.

[deprecated in 6.0] QDataStream &operator>>(QDataStream &s, QVariant::Type &p)

This function is deprecated since 6.0. We strongly advise against using it in new code.

Stream QMetaType::Type instead.

Reads a variant type p in enum representation from the stream s.