[英]Preserve QbyteArray to Qstring
I want to display the value of QbyteArray like how qDebug() displays it. 我想像qDebug()一样显示QbyteArray的值。
qDebug()<<byteArray === Displays -> "\x8E\xA9\xF3\xA5"
how do you grab this QbyteArray into a QString, when i do the convertion found online it gives me " ????
" as an output . 当我在线上进行转换时,如何将这个QbyteArray捕获到QString中,它给了我“
????
”作为输出。
I would like the content of the QString is the same as the output of the QDebug(); 我希望QString的内容与QDebug()的输出相同;
"\x8E\xA9\xF3\xA5"
so that QString string would contain "\\x8E\\xA9\\xF3\\xA5" 这样QString字符串将包含“ \\ x8E \\ xA9 \\ xF3 \\ xA5”
Build a QDebug object using the constructor: 使用构造函数构建一个QDebug对象:
QDebug::QDebug(QString *string)
QDebug :: QDebug(QString * string)
Constructs a debug stream that writes to the given string.
构造一个写入给定字符串的调试流。
Example: 例:
#include <QApplication>
#include <QDebug>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label;
QByteArray ba("\x8E\xA9\xF3\xA5");
QString res;
QDebug db(&res);
db << ba;
label.setText(res);
label.show();
return a.exec();
}
Update: 更新:
without "\\x", use toHex(): 如果没有“ \\ x”,请使用toHex():
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLabel label;
QByteArray ba("\x8E\xA9\xF3\xA5");
label.setText(ba.toHex());
label.show();
return a.exec();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.