PDA

View Full Version : QDatastream operate QPoint



samzhcs1
4th November 2016, 03:37
Hello, I wrote a nibble code to test QDatastream, and set one break point at line 7.
Environment is Qt5, QtCreator.
But in QtCreator, when the program stopped at Line 7, in Local and Expression view, the tmp value is (0, 0), supposed to be (6,11).

Dont' know why tmp is not (6,11).

Many thanks in advance.

1, QPoint pos(6,11);
2, QPoint tmp;
3, QByteArray datagram;

4, QDataStream out(&datagram, QIODevice::ReadWrite);
//out.setVersion(QDataStream::Qt_4_3);

5, out << pos;
6, out >> tmp;
7, return 0;

anda_skoa
4th November 2016, 10:04
My guess is that the stream is "atEnd" when you write into it, so the >> operator creates a defalt QPoint since there is no data to read.

You could add an "out.atEnd()" before line 6 to check if that theory holds.

Cheers,
_