#include <QCoreApplication>
#include<QVariant>
#include<QDebug>
#define cout qDebug()
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QVariant v(2);
QVariant v1("HELLO");
QVariant v2(QByteArray("HELLO"));
cout.noquote()<<v<<v1<<v2<<endl;
cout<<v<<v1<<v2<<endl;
cout<<v2;
int tmp=v.toInt();
cout<<tmp;
cout.noquote()<<v1.toString();
//----------------------------------
if(v1.canConvert<int>())
{
cout<<"可以";
}
else
{
cout<<"不能";
}
//第二种转换方法
cout<<v.value<int>()<<endl;
cout<<v.typeName()<<endl<<v.type();
cout<<"------------"<<endl;
cout<<v1.nameToType("2sadjk")<<endl;
return a.exec();
}
QT中QVariant的初使用
最新推荐文章于 2024-06-27 14:39:09 发布