- 字符串与进制转换的例子
/**
* @brief Widget::on_btnCalcHex_clicked 从界面上获取十六进制字符串,然后转为十进制和二进制字符串写回界面
*/
void Widget::on_btnCalcHex_clicked()
{
QString strHex = ui->editHex->text();// 十六进制的字符串
bool *ok = nullptr;
int dec = strHex.toInt(ok, 16);// 转为十进制
QString strBin = strHex.setNum(dec, 2);// 将十进制转为二进制的字符串
QString strDec = strHex.setNum(dec, 10);// 将十进制数转为十进制字符串
ui->editBin->setText(strBin);
ui->editDec->setText(strDec);
}
标签:QT5,12,ui,QString,字符串,dec,十进制,strHex
From: https://www.cnblogs.com/echo-lovely/p/17219350.html