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

📄 qvariant.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    Reads a variant \a p from the stream \a s.    \sa \link datastreamformat.html Format of the QDataStream    operators \endlink*/QDataStream& operator>>(QDataStream &s, QVariant &p){    p.load(s);    return s;}/*!    Writes a variant \a p to the stream \a s.    \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 << (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.*/#define Q_VARIANT_TO(f) \Q##f QVariant::to##f() const { \    if (d.type == f) \        return *v_cast<Q##f >(&d); \    Q##f ret; \    handler->convert(&d, f, &ret, 0); \    return ret; \}Q_VARIANT_TO(StringList)Q_VARIANT_TO(Date)Q_VARIANT_TO(Time)Q_VARIANT_TO(DateTime)Q_VARIANT_TO(ByteArray)Q_VARIANT_TO(Char)Q_VARIANT_TO(Url)Q_VARIANT_TO(Locale)Q_VARIANT_TO(RegExp)#ifndef QT_NO_GEOM_VARIANTQ_VARIANT_TO(Size)Q_VARIANT_TO(SizeF)Q_VARIANT_TO(Rect)Q_VARIANT_TO(Point)Q_VARIANT_TO(PointF)Q_VARIANT_TO(LineF)Q_VARIANT_TO(Line)Q_VARIANT_TO(RectF)#endif/*!    \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()*//*!    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{    if (d.type == String)        return *reinterpret_cast<const QString *>(&d.data.ptr);    QString ret;    handler->convert(&d, String, &ret, 0);    return ret;}/*!    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{    if (d.type != Map)        return QMap<QString, QVariant>();    return *v_cast<QVariantMap>(&d);}/*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    \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()*//*!    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{    if (d.type == BitArray)        return *v_cast<QBitArray>(&d);    return QBitArray();}/*!    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{    if (d.type == Int) {        if (ok)            *ok = true;        return d.data.i;    }    bool c = canConvert(Int);    if (ok)        *ok = c;    int res = 0;    if (c)        handler->convert(&d, Int, &res, ok);    return res;}/*!    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{    if (d.type == UInt) {        if (ok)            *ok = true;        return d.data.u;    }    bool c = canConvert(UInt);    if (ok)        *ok = c;    uint res = 0u;    if (c)        handler->convert(&d, UInt, &res, ok);    return res;}/*!    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{    if (d.type == LongLong) {        if (ok)            *ok = true;        return d.data.ll;    }    bool c = canConvert(LongLong);    if (ok)        *ok = c;    qlonglong res = Q_INT64_C(0);    if (c)        handler->convert(&d, LongLong, &res, ok);    return res;}/*!    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{    if (d.type == ULongLong) {        if (ok)            *ok = true;        return d.data.ull;    }    bool c = canConvert(ULongLong);    if (ok)        *ok = c;    qulonglong res = Q_UINT64_C(0);    if (c)        handler->convert(&d, ULongLong, &res, ok);    return res;}/*!    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{    if (d.type == Double) {        if (ok)        *ok = true;        return d.data.d;    }    bool c = canConvert(Double);    if (ok)        *ok = c;    double res = 0.0;    if (c)        handler->convert(&d, Double, &res, ok);    return res;}/*!    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{    if (d.type == List)        return *v_cast<QVariantList>(&d);    QVariantList res;    handler->convert(&d, List, &res, 0);    return res;}/*! \fn QVariant::canCast(Type t) const    Use canConvert() instead.*//*! \fn QVariant::cast(Type t)    Use convert() instead.*//*!    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    \header \o Type \o Automatically Cast To    \row \o \l Bool \o \l Char, \l Double, \l Int, \l LongLong, \l St

⌨️ 快捷键说明

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