為了避免每次找了半天的資料,最後又要重新找過一遍,因此蕾咪將計就計會做個摘要整理。
方便自己以後查找,省得浪費了大多數的時間再找資料,而不是真正的實作Q__________Q”
哈哈 當然,如果有人找到了需要的文章,我也會很高興的。
# QString →Number
1. QString→Double
QString qStr=”3.1416″;
double dNum=qStr.toDouble();
2. QString→Float
QString qStr=”3.1416″;
float fNum=qStr.toFloat();
3. QString→Int
Qstring str=”FF”;
bool ok;
int dec=str.toInt(&ok,10); //dec=255 ; ok=true
int hex =str.toInt(&ok,16); //hex=255;ok=true;
# Number →QString
1. Double →QString
double dNum = 3.1;
QString qStr = QString::number( dNum, ‘d’, 2 ); //qStr = 3.10
2. Float→QString
float fNum = 3.1;
QString qStr = QString::number( fNum, ‘f’, 2 ); //qStr = 3.10
3. Int→QString
int index=3;
QString qStr = QString::number(index); //qStr = 3
# QString←→Char*
1. QString → Char*
QString qStr1 = “QStr1”;
QByteArray qArr = qStr1.toLatin1();
const char *cStr2 = qArr.data();
printf(“Char* = %s”, cStr2);
2. Char*→QString
char qChar[10] = “QChar”;
QString qStr = QString(qChar);
# Multiple Variable→QString
char qChar[10] = “Hi”;
int qInt = 9527;
QString qStr = QString(“Wow %1 qInt %2 failed!”).arg(qChar).arg(qInt);
# Chinese→QString
QString qStr = QString::fromLoacal8Bit(“這是中文字。”);
#Chines eand Multiple Variable→QString
char qChar[10] = “Hi”;
int qInt = 9527;
QString qStr = QString::fromLoacal8Bit(“這是中文字 %1, 你好%2”).arg(qChar).arg(qInt);