一、QString的转换
QString转QByteArray
QByteArray byte; QString string; byte = string.toLatin1();
QString转String
QString string; std::string str; str = string.toStdString();
QString转char *
QString string; char *ch; ch = string.toLatin1.data();
QString转QHostAddress
QString string; QHostAddress address(string);
QString转int
QString string; int m; m=string.toInt();
QString转unsigned char
QString string; bool ok; unsigned char uch = string.toInt(&ok, 16);
二、String的转换
String转QString
QString string; std::string str; string = QString::fromStdString(str);
三、QByteArray的转换
QByteArray转char *
char *ch; //不能定义成ch[n],数组和指针不一样; QByteArray byte; ch = byte.data();
QByteArray转QString
QByteArray byte; QString string; string = QString(byte);
四、char、数组、指针的转换
char *转QByteArray
char *ch; QByteArray byte; byte = QByteArray(ch);
char *转QString
char *ch; QString string= QString(QLatin1String(ch));
QHostAddress转QString
QHostAddress address; QString string = address.toString();
unsigned char转QString
unsigned char uch; QString string = QString::number(uch,16);
五、int类型的转换
int转QString
int m; QString string; string=QString::number(m);