您的位置:首页 > 编程语言 > Qt开发

qt 学习小节

2014-06-26 21:49 926 查看
字符串转化成字节序列
QString------->QByteArray

1)
QByteArray QString::toLatin1() const
Returns a Latin-1 representation of the string as a QByteArray.

The returned byte array is undefined if the string contains non-Latin1 characters. Those characters may be suppressed or replaced with a question mark.
2)
QByteArray bytes = QByteArray::fromHex("010304000008");

qDebug("%#x",bytes.at(1));// 03

QByteArray QByteArray::fromHex(const QByteArray & hexEncoded) [static]
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!"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  qt type