今天遇到一个问题,想要实现一种功能:在QLineEdit中书写16进制字符串比如 00 01 ff,然后保存为16进制转换后的字节形式到内存中,然后在文件中进行查找字符串匹配,后来发现QByteArray QByteArray::fromHex(const QByteArray & hexEncoded)函数可以实现这个功能。
QByteArray QByteArray::fromHex(const QByteArray & hexEncoded)
Returns a decoded copy of the hex encoded array hexEncoded. Input is not checked for validity; invalid characters in the input are skipped, enabling the decoding process to continue with subsequent characters.
For example:
QByteArray text = QByteArray::fromHex("517420697320677265617421");
text.data(); // returns "Qt is great!"
<