QString 类求助

gxlsunday 2013-07-23 04:37:18
QByteArray byte_data=tcplink->readAll();
QString str = byte_data.toHex().data();
最近看别人写的代码,byte_data.toHex().data();什么意思看不明白
望各位高手扫盲!谢谢
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiuxianshen 2013-07-24
  • 打赏
  • 举报
回复
QByteArray QByteArray::toHex() const Returns a hex encoded copy of the byte array. The hex encoding uses the numbers 0-9 and the letters a-f. char * QByteArray::data() Returns a pointer to the data stored in the byte array. The pointer can be used to access and modify the bytes that compose the array. The data is '\0'-terminated, i.e. the number of bytes in the returned character string is size() + 1 for the '\0' terminator. toHex()将QByteArray转换成16进制,data()将QByteArray转换成char*, 然后利用QString的拷贝构造函数将char*转换成QString
xcyl 2013-07-24
  • 打赏
  • 举报
回复
楼上两位的 +10086
_Gx 2013-07-24
  • 打赏
  • 举报
回复
先转成16进制,再转成QString
dext 2013-07-23
  • 打赏
  • 举报
回复
将 ByteArray 中的实际数据,变成十六进制的字符串显示出来。 如果以前的ByteArray 是 ['Q', 't'] toHex 变成了 ['5','1','7','4'] 在data 变成QString 的 ‘5174’

21,489

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧