首页 > 编程知识 正文

QT基础之QVariant类

时间:2023-05-03 08:46:30 阅读:27792 作者:1818

文章目录

了解更多信息

QT基础和实例的应用目录

QVariant类类似于c的合并数据类型,可以存储许多QT类型的值,如QColor、QBrush、QFont、QPen、QRect、QString和QSize,也可以存储QT容器类型的值

GitHub链接: GitHub

QQ v { 709 }; q调试(v.toint ); //709 QVariant w{'Hello World'}; q调试(w; //qvariant(qstring,' hello world ' (q debug ) ) w.toString ); //'Hello World' QMapQString,QVariantmap{{'int ',709},{'double ',3.14}}; map['string']='Hello World '; map.insert('color ',qcolor ) ) 255,0,0 ); //相应的转换函数q debug (map [ ' int ' ] map [ ' int ' ].toint ); //qvariant(int,709 ) 709调试) ) map [ ' double ' ] map [ ' double ' ].to double ); //qvariant (双精度,3.14 ) 3.14调试) ) map [ '字符串' ] map [ '字符串' ].tostring ); //qvariant(qstring,' Hello World ' )、Hello World' qDebug )、map [ ' color ' ] map [ ' color ' ].valueqcolor ); //qvariant(qcolor,qcolor ) arg B1,1,0,0 ) ) qcolor ) arg B1,1,0,0 ) QStringList sl; sl 'A' 'B' 'C' 'D '; QVariant vt{sl}; if (vt.type (==qvariant :3360字符串列表) { auto list=vt.toStringList ); for(intI=0; ilist.size (; I ) { qDebug () list.at(i ) I; }c的各种初始化方式

q调试(映射)颜色(映射) )颜色(颜色).valueqcolor ); 将QColor对象保存在QVariant变量中,并使用模板QVariant:value ()返回QColor。 QVariant是QtCOre模块的类,不为QtGui模块(如QColor、QImage和QPixmap )中的数据类型提供转换函数。 必须使用QVariant:value ()或QVariantValue () )

QVariant:type ()函数返回存储在QVariant变量中的有价值的数据类型。 qvariant :字符串列表是QVariant:type ()枚举类型的变量。

这个枚举可以看到源代码qvariant.h

enum type { invalid=qmetatype :3360 unknown type,Bool=QMetaType:Bool,Int=QMetaType:Int, uint=qmetatype 33603360 longlong=qmetatype 33603360 longlong,ulonglong=qmetatype 3360: ulonglong,double=qmetatype 3360 Char=QMetaType:QChar,map=qmetatype :3360 qvariantmap,list=qmetatype :3360 qvariantlist, string=qmetatype 33603360 qvariantlist string list=qmetatype 33603360 qstring list,bytearray=qmetatype :3360 q bytearrray, bitarray=qmetatype 33603360 qbit array date=qmetatype 33603360 q date,Time=QMetaType:QTime,datetime=qmetatype URL=qmetatype 3360 locale=qmetatype 33603360 qlocale,Rect=QMetaType:QRect,rectf=qmetatype : qrectf, size=qmetatype 3360 qrectf sizef=qmetatype :3360 q sizef,Line=QMetaType:QLine,linef=qmetatype : qlion point=qmetatype : qlin ef pointf=qmetatype :3360 qpointf,regexp=qmetatype 33603360 qregexp, regular expression=qmetatype 33603360 qregularexpprexpression=qmetatype 3603360 hash=qmetatype :3360 qvarianthash, easing curve=qmetatype :3360 qeasingcurve,uuid=qmetatype33603360quid,#ifQt_config(itemmodel ) modelindex=qmetatype persistentmodelindex=qmetatype 33603360 qpersisten0# endiflastcoretype=qmetatype :3360 lastcoretype,font=qmetatype 3360 pixmap=qmetatype 33603360 qpixmap brush=qmetatype :3360 QB rush,color=qmetatype : q color,palette=qmetatype : image=qmetatte polygon=qmetatype :3360 qpolygon,region=qmetatype 33603360 q region,bitmap=qmetatype 3360: q bitmap cursor=qmap key sequence=qmetatype :3360 qkey sequence,Pen=QMetaType:QPen,textlength=qmetatype 3360360 qtexpe text format=qmetatype :3360 qtext format,matrix=qmetatype :3360 q矩阵, transform=qmetatype 33603360 qtransform矩阵4x4=qmetatype 33603360 q矩阵4x 4,vector 2d=qmetatype :3360 q vector 2d, vector 3d=qmetatype 33603360 q vector 3d vector 4d=qmetatype 33603360 q vector 4d,quaternion=qmetatype 33603360 quaternion, polygonf=qmetatype 33603360 qpolygonion icon=qmetatype :3360 qi con,lastguitype=qmetatype 33603360 lastguitype, size policy=qmetatype 33603360 qsizepolicy,usertype=qmetatype:user,last type=0x fffffffffff//needthissothatgcc 我希望我的文章对大家有帮助。 由于个人能力的局限性,文章可能有一些问题。 欢迎您的指正和补充。

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。