一、HTuple→VC 数据类型转换:
//HTuple转int HTuple hTuple = 1; int str1 = hTuple[0].I(); // str1 = 1 //HTuple转double 常用 HTuple hTuple = 1.1; double str2 = hTuple[0].D(); // str2 = 1.1 //HTuple转CString HTuple hTuple = "cstring"; CString str3 = hTuple[0].S(); // str3 = "cstring"
二、VC→HTuple 数据类型转换:HTuple
和int
、double
、CString
、QString
之间的数据转换
int str1 = 1; double str2 = 1.1; CString str3 = "CString"; QString str4 = "QString"; HTuple hTuple2; hTuple2[0] = str1; // hTuple2[0].I() = 1 hTuple2[1] = str2; // hTuple2[1].D() = 1.1 hTuple2[2] = str3.GetBuffer(); // hTuple2[2].S() = "CString" hTuple2[3] = str4.toStdString().c_str(); // hTuple2[3].S() = "QString" int i = hTuple2[0].I(); // i=1 double d = hTuple2[1].D(); // d=1.1 CString cstring = hTuple2[2].S(); // cstring = "CString" QString qstring = hTuple2[3].S(); // qstring = "QString"
三、double→QString数据类型转换:
① 直接转换
double m1 = 66.123456; QString str1 = QString::number(m2);
② .arg
的方式保留3位小数则写法如下:
double m2 = 66.123456; QString str2 = QString("%1").arg(m2, 0, 'f', 3); //3是保留三位小数 qDebug()<<str2;
输出结果为:66.123
③ 如果想控制整数加小数在总位数,则写法如下:
double m3 = 66.123456; QString str3 = QString("%1").arg(m3, 0, 'g', 6); //6是保留总位数 qDebug()<<str3;
输出结果为:66.1235
四、QString数据类型中文乱码解决:
//QString类型的中文需要做如下转换 QString::fromStdWString(L"中文")