data<<(quint16(0))<<quint8('S');
data<<message;
data<<(quint8('L'));
data.device()->seek(0);
data<<(arr.size()-sizeof(quint16)); // How many bytes are being written here?
tBrowser
->append
(QString::number(type2
));
QDataStream data(&arr,QIODevice::ReadWrite);
data.setVersion(QDataStream::Qt_4_6);
data<<(quint16(0))<<quint8('S');
data<<message;
data<<(quint8('L'));
data.device()->seek(0);
data<<(arr.size()-sizeof(quint16)); // How many bytes are being written here?
tBrowser->append(QString::number(type2));
To copy to clipboard, switch view to plain text mode
When I try a quick test:
data<< quint16(0xBEEF) <<quint8('S');
data<<message;
data<<(quint8('L'));
qDebug() << arr.toHex();
data.device()->seek(0);
data << (arr.size() - sizeof(quint16));
qDebug() << arr.toHex();
data.device()->seek(0);
QString message("ABCDEF");
QByteArray arr;
QDataStream data(&arr,QIODevice::ReadWrite);
data.setVersion(QDataStream::Qt_4_6);
data<< quint16(0xBEEF) <<quint8('S');
data<<message;
data<<(quint8('L'));
qDebug() << arr.toHex();
data.device()->seek(0);
data << (arr.size() - sizeof(quint16));
qDebug() << arr.toHex();
data.device()->seek(0);
To copy to clipboard, switch view to plain text mode
I get 18 bytes (0x00000012 bytes) excluding the size field:
"beef530000000c0041004200430044004500464c"
"0000001200000c0041004200430044004500464c"
"beef530000000c0041004200430044004500464c"
"0000001200000c0041004200430044004500464c"
To copy to clipboard, switch view to plain text mode
I think you can see the problem now.
PS: Were you expecting Unicode characters at the receiving end?
Bookmarks