标签:
一、QVaraint简介
QDataStream out(...);
QVariant v(123); // The variant now contains an int
int x = v.toInt(); // Writes a type tag and an int to out
v = QVariant("hello");// The variant now contains a QByteArray
v = QVariant(tr("hello")); // The variant now contains a QString
int y = v.toInt(); // y = 0 since v cannot be converted to an int
QString s = v.toString(); // s = tr("hello") (see QObject::tr())
out << v; // Writes a type tag and a QString to out
...
- QDataStream in(...); // (opening the previously written stream)
in >> v; // Reads an Int variant
int z = v.toInt(); // z = 123
qDebug("Type is %s", // prints "Type is int"
v.typeName());
v = v.toInt() + 100; // The variant now hold the value 223
v = QVariant(QStringList());你甚至可以存储QList<QVariant>和QMap<QString ,QVariant>.
标签:
原文地址:http://www.cnblogs.com/chengkeke/p/5417430.html