(1)char*转QString
char* pages;
QString inputpage = QString(QLatin1String(pages));
(2)QString转char*
QString str;
char* ch;
QByteArray ba = str. toLocal8Bit(); // must
ch=ba.data();
(3)QString转换string
string dome1;
QString dome2;
dome1 = dome2.toStdstring();
(4)string转化为QString
string dome1;
QString dome2;
dome2 = QString::fromestdstring(dome1);
(5)string转化char*
string dome1;
char dome2[20];
dome = dome1.c_str();
(6)char*转化为string
char dome1[20] = "hello world!";
string dome2(dome1);
(7)int/float/double转QString
long a = 63;
QString s = QString::number(a, 10); // s == "63"
QString t = QString::number(a, 16).toUpper(); // t == "3F"
(8)QString转int/float/double
QString str="123.45";
double val=str.toDouble();
float val=str.toFloat();
int val=str1.toInt();
(9)QString转wstring(QString 转 BSTR)
QString qstr;
BSTR bstr = SysAllocStringLen((OLECHAR*)qstr.unicode(), qstr.length());
BSTR bstr = SysAllocString((OLECHAR*)qstr.unicode());
C++各种类型的char*、QString、string、wstring、BSTR格式相互转化
最新推荐文章于 2022-06-15 17:23:21 发布