1. 数字转换字符串
QString Num2Str(quint8 hex) { QString str = QString("%1").arg(hex, 0, 10); return str; }
2. 数字转换数字
1. int Num2Num(quint8 hex) 2. { 3. QString str = QString("%1").arg(hex, 0, 10); 4. int res = num.toInt(); 5. return res; 6. }
3. 字符串转换数字
1. int Str2Num(QString str) 2. { 3. bool ok; 4. int res = str.toInt(&ok, 16); 5. return res; 6. }
4. 字符串转换字符串
QString Str2Str(QString str) { bool ok; int res = str.toInt(&ok, 16); QString str_ = QString("%1").arg(res , 0, 10); return str_; }
1. 数字转换字符串
QByteArray Num2Str(int num) { QByteArray arr; arr.setNum(num, 16); return arr; }
2. 数字转换数字
QByteArray Str2Num(QString str) { QByteArray arr; arr.setNum(str.toInt(), 16); return arr; }
3. 字符串转换数字
QByteArray Str2Num(QString str) { QByteArray arr; arr.setNum(str.toInt(), 16); return arr; }
4. 字符串转换字符串
QString Str2Str(QString str) { QString str_= QString("%1").arg(str.toInt(),0,16); return str_; }
三、终极秘诀
uint32_t tmp = static_cast<uint32_t>(hex.toUInt(nullptr, 16));