?? qvariant.cpp
字號:
\l ULongLong; otherwise returns an empty string. \sa canConvert(), convert()*/QString QVariant::toString() const{ return qVariantToHelper<QString>(d, String, handler);}/*! Returns the variant as a QMap<QString, QVariant> if the variant has type() \l Map; otherwise returns an empty map. \sa canConvert(), convert()*/QVariantMap QVariant::toMap() const{ return qVariantToHelper<QVariantMap>(d, Map, handler);}/*! \fn QDate QVariant::toDate() const Returns the variant as a QDate if the variant has type() \l Date, \l DateTime, or \l String; otherwise returns an invalid date. If the type() is \l String, an invalid date will be returned if the string cannot be parsed as a Qt::ISODate format date. \sa canConvert(), convert()*/QDate QVariant::toDate() const{ return qVariantToHelper<QDate>(d, Date, handler);}/*! \fn QTime QVariant::toTime() const Returns the variant as a QTime if the variant has type() \l Time, \l DateTime, or \l String; otherwise returns an invalid time. If the type() is \l String, an invalid time will be returned if the string cannot be parsed as a Qt::ISODate format time. \sa canConvert(), convert()*/QTime QVariant::toTime() const{ return qVariantToHelper<QTime>(d, Time, handler);}/*! \fn QDateTime QVariant::toDateTime() const Returns the variant as a QDateTime if the variant has type() \l DateTime, \l Date, or \l String; otherwise returns an invalid date/time. If the type() is \l String, an invalid date/time will be returned if the string cannot be parsed as a Qt::ISODate format date/time. \sa canConvert(), convert()*/QDateTime QVariant::toDateTime() const{ return qVariantToHelper<QDateTime>(d, DateTime, handler);}/*! \fn QByteArray QVariant::toByteArray() const Returns the variant as a QByteArray if the variant has type() \l ByteArray or \l String (converted using QString::fromAscii()); otherwise returns an empty byte array. \sa canConvert(), convert()*/QByteArray QVariant::toByteArray() const{ return qVariantToHelper<QByteArray>(d, ByteArray, handler);}#ifndef QT_NO_GEOM_VARIANT/*! \fn QPoint QVariant::toPoint() const Returns the variant as a QPoint if the variant has type() \l Point or \l PointF; otherwise returns a null QPoint. \sa canConvert(), convert()*/QPoint QVariant::toPoint() const{ return qVariantToHelper<QPoint>(d, Point, handler);}/*! \fn QRect QVariant::toRect() const Returns the variant as a QRect if the variant has type() \l Rect; otherwise returns an invalid QRect. \sa canConvert(), convert()*/QRect QVariant::toRect() const{ return qVariantToHelper<QRect>(d, Rect, handler);}/*! \fn QSize QVariant::toSize() const Returns the variant as a QSize if the variant has type() \l Size; otherwise returns an invalid QSize. \sa canConvert(), convert()*/QSize QVariant::toSize() const{ return qVariantToHelper<QSize>(d, Size, handler);}/*! \fn QSizeF QVariant::toSizeF() const Returns the variant as a QSizeF if the variant has type() \l SizeF; otherwise returns an invalid QSizeF. \sa canConvert(), convert()*/QSizeF QVariant::toSizeF() const{ return qVariantToHelper<QSizeF>(d, SizeF, handler);}/*! \fn QRectF QVariant::toRectF() const Returns the variant as a QRectF if the variant has type() \l Rect or \l RectF; otherwise returns an invalid QRectF. \sa canConvert(), convert()*/QRectF QVariant::toRectF() const{ return qVariantToHelper<QRectF>(d, RectF, handler);}/*! \fn QLineF QVariant::toLineF() const Returns the variant as a QLineF if the variant has type() \l LineF; otherwise returns an invalid QLineF. \sa canConvert(), convert()*/QLineF QVariant::toLineF() const{ return qVariantToHelper<QLineF>(d, LineF, handler);}/*! \fn QLine QVariant::toLine() const Returns the variant as a QLine if the variant has type() \l Line; otherwise returns an invalid QLine. \sa canConvert(), convert()*/QLine QVariant::toLine() const{ return qVariantToHelper<QLine>(d, Line, handler);}/*! \fn QPointF QVariant::toPointF() const Returns the variant as a QPointF if the variant has type() \l Point or \l PointF; otherwise returns a null QPointF. \sa canConvert(), convert()*/QPointF QVariant::toPointF() const{ return qVariantToHelper<QPointF>(d, PointF, handler);}#endif // QT_NO_GEOM_VARIANT/*! \fn QUrl QVariant::toUrl() const Returns the variant as a QUrl if the variant has type() \l Url; otherwise returns an invalid QUrl. \sa canConvert(), convert()*/QUrl QVariant::toUrl() const{ return qVariantToHelper<QUrl>(d, Url, handler);}/*! \fn QLocale QVariant::toLocale() const Returns the variant as a QLocale if the variant has type() \l Locale; otherwise returns an invalid QLocale. \sa canConvert(), convert()*/QLocale QVariant::toLocale() const{ return qVariantToHelper<QLocale>(d, Locale, handler);}/*! \fn QRegExp QVariant::toRegExp() const \since 4.1 Returns the variant as a QRegExp if the variant has type() \l RegExp; otherwise returns an empty QRegExp. \sa canConvert(), convert()*/QRegExp QVariant::toRegExp() const{ return qVariantToHelper<QRegExp>(d, RegExp, handler);}/*! \fn QChar QVariant::toChar() const Returns the variant as a QChar if the variant has type() \l Char, \l Int, or \l UInt; otherwise returns an invalid QChar. \sa canConvert(), convert()*/QChar QVariant::toChar() const{ return qVariantToHelper<QChar>(d, Char, handler);}/*! Returns the variant as a QBitArray if the variant has type() \l BitArray; otherwise returns an empty bit array. \sa canConvert(), convert()*/QBitArray QVariant::toBitArray() const{ return qVariantToHelper<QBitArray>(d, BitArray, handler);}template <typename T>inline T qNumVariantToHelper(const QVariant::Private &d, QVariant::Type t, const QVariant::Handler *handler, bool *ok, const T& val){ if (ok) *ok = true; if (d.type == t) return val; T ret; if (!handler->convert(&d, t, &ret, ok) && ok) *ok = false; return ret;}/*! Returns the variant as an int if the variant has type() \l Int, \l Bool, \l ByteArray, \l Char, \l Double, \l LongLong, \l String, \l UInt, or \l ULongLong; otherwise returns 0. If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be converted to an int; otherwise \c{*}\a{ok} is set to false. \sa canConvert(), convert()*/int QVariant::toInt(bool *ok) const{ return qNumVariantToHelper<int>(d, Int, handler, ok, d.data.i);}/*! Returns the variant as an unsigned int if the variant has type() \l UInt, \l Bool, \l ByteArray, \l Char, \l Double, \l Int, \l LongLong, \l String, or \l ULongLong; otherwise returns 0. If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be converted to an unsigned int; otherwise \c{*}\a{ok} is set to false. \sa canConvert(), convert()*/uint QVariant::toUInt(bool *ok) const{ return qNumVariantToHelper<uint>(d, UInt, handler, ok, d.data.u);}/*! Returns the variant as a long long int if the variant has type() \l LongLong, \l Bool, \l ByteArray, \l Char, \l Double, \l Int, \l String, \l UInt, or \l ULongLong; otherwise returns 0. If \a ok is non-null: \c{*}\c{ok} is set to true if the value could be converted to an int; otherwise \c{*}\c{ok} is set to false. \sa canConvert(), convert()*/qlonglong QVariant::toLongLong(bool *ok) const{ return qNumVariantToHelper<qlonglong>(d, LongLong, handler, ok, d.data.ll);}/*! Returns the variant as as an unsigned long long int if the variant has type() \l ULongLong, \l Bool, \l ByteArray, \l Char, \l Double, \l Int, \l LongLong, \l String, or \l UInt; otherwise returns 0. If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be converted to an int; otherwise \c{*}\a{ok} is set to false. \sa canConvert(), convert()*/qulonglong QVariant::toULongLong(bool *ok) const{ return qNumVariantToHelper<qulonglong>(d, ULongLong, handler, ok, d.data.ull);}/*! Returns the variant as a bool if the variant has type() Bool. Returns true if the variant has type() \l Bool, \l Char, \l Double, \l Int, \l LongLong, \l UInt, or \l ULongLong and the value is non-zero, or if the variant has type \l String and its lower-case content is not empty, "0" or "false"; otherwise returns false. \sa canConvert(), convert()*/bool QVariant::toBool() const{ if (d.type == Bool) return d.data.b; bool res = false; handler->convert(&d, Bool, &res, 0); return res;}/*! Returns the variant as a double if the variant has type() \l Double, \l Bool, \l ByteArray, \l Int, \l LongLong, \l String, \l UInt, or \l ULongLong; otherwise returns 0.0. If \a ok is non-null: \c{*}\a{ok} is set to true if the value could be converted to a double; otherwise \c{*}\a{ok} is set to false. \sa canConvert(), convert()*/double QVariant::toDouble(bool *ok) const{ return qNumVariantToHelper<double>(d, Double, handler, ok, d.data.d);}/*! Returns the variant as a QVariantList if the variant has type() \l List or \l StringList; otherwise returns an empty list. \sa canConvert(), convert()*/QVariantList QVariant::toList() const{ return qVariantToHelper<QVariantList>(d, List, handler);}/*! \fn QVariant::canCast(Type t) const Use canConvert() instead.*//*! \fn QVariant::cast(Type t) Use convert() instead.*/static const quint32 qCanConvertMatrix[QVariant::LastCoreType + 1] ={/*Invalid*/ 0,/*Bool*/ 1 << QVariant::Double | 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::String | 1 << QVariant::Char,/*Int*/ 1 << QVariant::UInt | 1 << QVariant::String | 1 << QVariant::Double | 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::Char | 1 << QVariant::ByteArray,/*UInt*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double | 1 << QVariant::Bool | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::Char | 1 << QVariant::ByteArray,/*LLong*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::ULongLong | 1 << QVariant::Char | 1 << QVariant::ByteArray,/*ULlong*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::Double | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::LongLong | 1 << QVariant::Char | 1 << QVariant::ByteArray,/*double*/ 1 << QVariant::Int | 1 << QVariant::String | 1 << QVariant::ULongLong | 1 << QVariant::Bool | 1 << QVariant::UInt | 1 << QVariant::LongLong | 1 << QVariant::ByteArray,/*QChar*/ 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::LongLong | 1 << QVariant::ULongLong,/*QMap*/ 0,/*QList*/ 1 << QVariant::StringList,/*QString*/ 1 << QVariant::StringList | 1 << QVariant::ByteArray | 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::Bool | 1 << QVariant::Double | 1 << QVariant::Date | 1 << QVariant::Time | 1 << QVariant::DateTime | 1 << QVariant::LongLong | 1 << QVariant::ULongLong | 1 << QVariant::Char,/*QStringList*/ 1 << QVariant::List | 1 << QVariant::String,/*QByteArray*/ 1 << QVariant::String | 1 << QVariant::Int | 1 << QVariant::UInt | 1 << QVariant::Double | 1 << QVariant::LongLong | 1 << QVariant::ULongLong,/*QBitArray*/ 0,/*QDate*/ 1 << QVariant::String | 1 << QVariant::DateTime,/*QTime*/ 1 << QVariant::String | 1 << QVariant::DateTime,/*QDateTime*/ 1 << QVariant::String | 1 << QVariant::Date,/*QUrl*/ 0,/*QLocale*/ 0,/*QRect*/ 1 << QVariant::RectF,/*QRectF*/ 1 << QVariant::Rect,/*QSize*/ 1 << QVariant::SizeF,/*QSizeF*/ 1 << QVariant::Size,/*QLine*/ 1 << QVariant::LineF,/*QLineF*/ 1 << QVariant::Line,/*QPoint*/ 1 << QVariant::PointF,/*QPointF*/ 1 << QVariant::Point,/*QRegExp*/ 0};/*! Returns true if the variant's type can be cast to the requested type, \a t. Such casting is done automatically when calling the toInt(), toBool(), ... methods. The following casts are done automatically: \table \he
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -