QT问题:我用qDebug()输出QByteArray变量,为什么只能输出一个” ?

2025-05-20 11:09:55
推荐回答(1个)
回答1:

The QByteArray class provides an array of bytes.QByteArray can be used to store both raw bytes (including '\0's) and traditional 8-bit '\0'-terminated strings. Using QByteArray is much more convenient than using const char *. Behind the scenes, it always ensures that the data is followed by a '\0' terminator, and uses implicit sharing (copy-on-write) to reduce memory usage and avoid needless copying of data.

这样你就可以遍历了:
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
cout << "[" << *data << "]" << endl;
++data;
}