That's not the point. Using "&a" you are still sending a pointer (and not a reference). You need to send the data, for instance:
struct abc {
char a;
char b;
};
QDataStream& operator<<(QDataStream& stream, const abc &object) {
stream << object.a << object.b;
return stream;
}
QDataStream& operator>>(QDataStream& stream, abc &object) {
stream >> object.a >> object.b;
return stream;
}
struct abc {
char a;
char b;
};
QDataStream& operator<<(QDataStream& stream, const abc &object) {
stream << object.a << object.b;
return stream;
}
QDataStream& operator>>(QDataStream& stream, abc &object) {
stream >> object.a >> object.b;
return stream;
}
To copy to clipboard, switch view to plain text mode
and then you can do:
abc a;
a.a = '1';
a.b = '2';
str << a;
socket->write(data); // btw. such code is practically useless,
// the receiver doesn't know how much data to expect
abc a;
a.a = '1';
a.b = '2';
QByteArray data;
QDataStream str(&data);
str << a;
socket->write(data); // btw. such code is practically useless,
// the receiver doesn't know how much data to expect
To copy to clipboard, switch view to plain text mode
Being lazy and trying to dump a memory block directly into the data stream is usually a bad idea.
Bookmarks