QT问题:我用qDebug()输出QByteArray变量,为什么只能输出一个” ? 5
我在写TCP的客户端,以下代码是其中一个按键的槽代码如下:voidtcpClient::on_RunProcessButton_clicked(){message=tr(...
我在写TCP的客户端,以下代码是其中一个按键的槽
代码如下:
void tcpClient::on_RunProcessButton_clicked()
{
message=tr("run ComputeLine\r\n"); //message是QString变量
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
out<<quint16(0)<<message;
out.device()->seek(0);
out<<quint16(sizeof(block)-sizeof(quint16));
qDebug()<<block; //qDebug输出检查block数据
Client->write(block);
}
qdebug的输出结果是:“
为什么会这样? 展开
代码如下:
void tcpClient::on_RunProcessButton_clicked()
{
message=tr("run ComputeLine\r\n"); //message是QString变量
QByteArray block;
QDataStream out(&block,QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
out<<quint16(0)<<message;
out.device()->seek(0);
out<<quint16(sizeof(block)-sizeof(quint16));
qDebug()<<block; //qDebug输出检查block数据
Client->write(block);
}
qdebug的输出结果是:“
为什么会这样? 展开
展开全部
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;
}
这样你就可以遍历了:
QByteArray ba("Hello world");
char *data = ba.data();
while (*data) {
cout << "[" << *data << "]" << endl;
++data;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询