【发布时间】:2022-11-10 23:44:20
【问题描述】:
QString samp_buff[100];
QByteArray data;
uint8_t speed;
samp_buff[3] = data.toHex(); //I converted the QByteArray into a string
qDebug() << "read_every_data_"<< samp_buff[3];
speed = samp_buff[3].toUInt(); //Trying to convert the string to uint8_t
qDebug() << "Converted to UINT8" << speed;
你好!我成功地将 Qbytearray 值(数据)作为字符串存储在 samp_buff 字符串中,并且还在以十六进制形式将 QString 转换为 Uint8_t 期间。
Data: "\x07" //QByteArray
read_every_data_ "07" //QString
Converted to UINT8 7 //Uint8_t
它为此工作正常,但发生这种情况时会出现问题。
Data: "\x0B" //QByteArray
read_every_data_ "0b" //QString
Converted to UINT8 0 //Uint8_t
每当十六进制值中包含字母时,从 qString 到 uint8_t 的转换都会归零。
【问题讨论】:
标签: c++ qt uint8t qbytearray