QString 类型转换

因为经常用到类型转换,看到一篇很全的文章,就记下来,方便以后使用。

1.QString int

QString str

int m

m = str.toInt();

2.int QString

QString str

int m

str = QString::number(m);

3.unsigned char QString

unsigned char uch;

uch = QString::numbere(uch,16);//这种方法,如果转0x06 这种0在前的数据就会转成6

3.1

QString str;

str.sprintf("%02x",uch);

4.Qstring unsigned char

QString str;

unsigned char uch;

QByteArray ba = str.toLatin1();//QStringQByteArray

uch = ba.data();

5.QStringString

QString string;

std::string str;

str = string.toStdString();

6.StringQString

QString string;

std::string str;

string = QString::fromStdString(str);

7.QByteArraychar *

char *ch;         //不能定义成ch[n],数组和指针不一样;
QByteArray byte;
ch = byte.data();

8.char *QByteArray

char *ch;
QByteArray byte;
byte = QByteArray(ch);

9.QHostAddressQString

QHostAddress address;

QString string = address.toString();

10.QStringQHostAddress

QString string;

QHostAddress address(string);




转自http://www.cnblogs.com/jiasaidongqi/p/4390145.html

你可能感兴趣的:(QT)