exam1.cpp

来自「精通QT4编程书籍光盘中的源码」· C++ 代码 · 共 33 行

CPP
33
字号
// chapter15/variant/exam1.#include <QDebug>#include <QVariant>#include <QColor>int main(int argc, char *argv[]){	QVariant v(709);	qDebug() <<  v.toInt();	v = QVariant("How are you!");	qDebug() << v.toString();	QMap <QString, QVariant> map;	map["int"] = 709;	map["double"] = 709.709;	map["string"] = "How are you!";	map["color"] = QColor(255, 0, 0);	qDebug() << map["int"] << map["int"].toInt();	qDebug() << map["double"] << map["double"].toDouble();	qDebug() << map["string"] << map["string"].toString();	qDebug() << map["color"] << map["color"].value<QColor>();	QStringList sl;	sl << "A" << "B" << "C" << "D";	QVariant slv(sl);	if(slv.type() == QVariant::StringList)	{		QStringList list = slv.toStringList();		for(int i=0; i<list.size(); ++i)			qDebug() << list.at(i);	}    return 0;}

⌨️ 快捷键说明

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