2011-10-19 22 views

回答

0

這是一個很好的閱讀Model/View Programming in Qt的最佳做法。

以上鍊接底部的示例和鏈接也很好。

至於存儲多種類型,我會看看QVariant和QSettings;使用QVariant在Qt中的模型/視圖編程中被多次引用。

QVariant非常強大,適用於許多不同類型。它是從QSettings中讀取數值的核心。請務必閱讀QSettings的描述以獲取更多建議。

QBitArray toBitArray() const 
    bool   toBool() const 
    QByteArray toByteArray() const 
    QChar  toChar() const 
    QDate  toDate() const 
    QDateTime toDateTime() const 
    double  toDouble (bool * ok = 0) const 
    QEasingCurve toEasingCurve() const 
    float  toFloat (bool * ok = 0) const 
    QHash<QString, QVariant> toHash() const 
    int   toInt (bool * ok = 0) const 
    QLine  toLine() const 
    QLineF  toLineF() const 
    QList<QVariant> toList() const 
    QLocale  toLocale() const 
    qlonglong toLongLong (bool * ok = 0) const 
    QMap<QString, QVariant> toMap() const 
    QPoint  toPoint() const 
    QPointF  toPointF() const 
    qreal  toReal (bool * ok = 0) const 
    QRect  toRect() const 
    QRectF  toRectF() const 
    QRegExp  toRegExp() const 
    QSize  toSize() const 
    QSizeF  toSizeF() const 
    QString  toString() const 
    QStringList toStringList() const 
    QTime  toTime() const 
    uint   toUInt (bool * ok = 0) const 
    qulonglong toULongLong (bool * ok = 0) const 
    QUrl   toUrl() const 

另一個不錯的選擇是QString。它有許多內置的轉換也:)

QByteArray toAscii() const 
    QString  toCaseFolded() const 
    double  toDouble (bool * ok = 0) const 
    float   toFloat (bool * ok = 0) const 
    int   toInt (bool * ok = 0, int base = 10) const 
    QByteArray toLatin1() const 
    QByteArray toLocal8Bit() const 
    long   toLong (bool * ok = 0, int base = 10) const 
    qlonglong  toLongLong (bool * ok = 0, int base = 10) const 
    QString  toLower() const 
    short   toShort (bool * ok = 0, int base = 10) const 
    std::string toStdString() const 
    std::wstring toStdWString() const 
    uint   toUInt (bool * ok = 0, int base = 10) const 
    ulong   toULong (bool * ok = 0, int base = 10) const 
    qulonglong toULongLong (bool * ok = 0, int base = 10) const 
    ushort  toUShort (bool * ok = 0, int base = 10) const 
    QVector<uint> toUcs4() const 
    QString  toUpper() const 
    QByteArray toUtf8() const 
    int   toWCharArray (wchar_t * array) const 

當保存數值爲QString,一定要使用QString ::號碼(。

相關問題