⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qvariant.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    \sa \link datastreamformat.html Format of the QDataStream    operators \endlink*/QDataStream& operator<<(QDataStream &s, const QVariant &p){    p.save(s);    return s;}/*!    Reads a variant type \a p in enum representation from the stream \a s.*/QDataStream& operator>>(QDataStream &s, QVariant::Type &p){    quint32 u;    s >> u;    p = (QVariant::Type)u;    return s;}/*!    Writes a variant type \a p to the stream \a s.*/QDataStream& operator<<(QDataStream &s, const QVariant::Type p){    s << static_cast<quint32>(p);    return s;}#endif //QT_NO_DATASTREAM/*!    \fn bool QVariant::isValid() const    Returns true if the storage type of this variant is not    QVariant::Invalid; otherwise returns false.*/template <typename T>inline T qVariantToHelper(const QVariant::Private &d, QVariant::Type t,                          const QVariant::Handler *handler, T * = 0){    if (d.type == t)        return *v_cast<T>(&d);    T ret;    handler->convert(&d, t, &ret, 0);    return ret;}/*!    \fn QStringList QVariant::toStringList() const    Returns the variant as a QStringList if the variant has type()    StringList, \l String, or \l List of a type that can be converted    to QString; otherwise returns an empty list.    \sa canConvert(), convert()*/QStringList QVariant::toStringList() const{    return qVariantToHelper<QStringList>(d, StringList, handler);}/*!    Returns the variant as a QString if the variant has type() \l    String, \l Bool, \l ByteArray, \l Char, \l Date, \l DateTime, \l    Double, \l Int, \l LongLong, \l StringList, \l Time, \l UInt, or    \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()*/#ifndef QT_NO_REGEXPQRegExp QVariant::toRegExp() const{    return qVariantToHelper<QRegExp>(d, RegExp, handler);}#endif/*!    \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 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -