1. 使用QVariant 打印数字、打印字符串
2. 使用QMap,打印map项 VS 打印转换类型后的值
3. 使用QStringList ,并声明变量迭代打印该字符串列表
#include "QDebug"
#include "QVariant"
#include "QColor"
int main(int argc, char *argv[])
{
QVariant v(709);
qDebug()<<v.toInt();//打印709
QVariant w("How are you!");
qDebug()<<w.toString(); //打印 "How are you!"
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);
}
}
1298

被折叠的 条评论
为什么被折叠?



