目录
1. QString 转 int
调用函数:
int QString::toInt(bool *ok = nullptr, int base = 10) const
uint QString::toUInt(bool *ok = nullptr, int base = 10) const
1.1 十进制
代码块:
QString str = "63";
int num = str.toInt();
qDebug() << "str:" << str;
qDebug() << "num:" << num;
运行结果:
str: "63"
num: 63
1.2 任意进制
代码块:
QString str = "FF";
qDebug() << "str:" << str;
bool ok;
int hex = str.toInt(&ok, 16); // hex == 255, ok == true
qDebug() << "ok:" << ok;
qDebug() << "hex:" << hex;
int dec = str.toInt(&ok, 10); // dec == 0, ok == false
qDebug() << "ok:" << ok;
qDebug() << "dec:" << dec;
qDebug() << "=============== base == 0 ===============";
QString str1 = "0x63"; // 16进制
qDebug() << "str1:" << str1;
QString str2 = "063"; // 8进制
qDebug() <<