Questions tagged [qdatastream]

The QDataStream class provides serialization of binary data to a QIODevice.

The QDataStream class provides serialization of binary data to a QIODevice.

A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. For example, a data stream that is written by a PC under Windows can be read by a Sun SPARC running Solaris. One can also use a data stream to read/write raw unencoded binary data.

The QDataStream class implements the serialization of C++'s basic data types, like char, short, int, char *, etc. Serialization of more complex data is accomplished by breaking up the data into primitive units.

105 questions
1
vote
1 answer

QDataStream reads and writes more bytes than QFile::length() reports to have

I have a utility that should copy files from one location to another. The problem I have is when reading X bytes using the QDataStream and writing it, the number of bytes being read/written exceeds the number of bytes the file has. I see this…
CybeX
  • 2,060
  • 3
  • 48
  • 115
1
vote
1 answer

QDataStream read to QVector

I have a QByteArray containing 8 bits representing two floating-point numbers, what is the correct and simplest way to read QDataStream to QVector? Code: QByteArray ByteFloatArray; QVector
Kanal ik
  • 35
  • 3
1
vote
1 answer

Converting QImage to QByteArray using QDataStream

Im trying to convert a QImage that maked from ScreenShot to a QByteArray for sending via QTCPSocket. when i convert QImage to QByteArray and before sending it i try to deserialize and show it on label it cant ! what's my mistake? thx for…
H.M
  • 425
  • 2
  • 16
1
vote
0 answers

Incomplete data in QDataStream when reading from QTcpSocket

So I have a strange issue that when I read data (QDataStream) on a QTcpSocket: some of the data seems to be missing. The bytesAvailable() function will return the proper amount of bytes to be read, but QDataStream doesn't seem to hold all the…
RBL92
  • 21
  • 3
1
vote
0 answers

QFile.read() value into qDebug() into QDataStream

I was wondering why : QString MainWindow::getFileText(QString filename) { QFile test(filename + ".txt"); // The file who gets written into QFile file(filename); // The executable I am reading QDataStream in(&test); …
Nox
  • 713
  • 7
  • 16
1
vote
1 answer

Qt model drag & drop - Unable to save type QJsonValue

I have a QAbstractListModel to display a QJsonArray, with drag & drop implementation: class NoteListModel : public QAbstractListModel { Q_OBJECT public: explicit NoteListModel(QObject *parent = nullptr); ~NoteListModel() override; …
thibsc
  • 3,747
  • 2
  • 18
  • 38
1
vote
0 answers

QDataStream operator>> on a std::map, how to initialize without a default constructor?

first post on Stackoverflow! So to summarize my problem: I am trying to serialize a custom class, which contains a map of another custom class (std::map). So for serialization I have: QDataStream& operator<<(QDataStream& out, const std::map
trablazar
  • 25
  • 4
1
vote
1 answer

How to write binary data to stdout in Qt5

QTextStream allows me to wrap stdout so that I can write using Qt spesifics to stdout with conveneince. Example: QTextStream qout(stdout); qout << QString("Some qt spesific stuff: %1\n").arg(1337); However while QTextStream is really useful, it…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
1
vote
2 answers

QDataStream writing wrong values to QByteArray

I'm writing a simple TCP based network application in Qt and wanted to use QDataStream and QByteArray to send data over the network. The problem is that when I'm putting data into QByteArray they are "zeroed". For example (a slot in MainWindow that…
Kestrel
  • 29
  • 5
1
vote
0 answers

Qt Serialization no match for operator << operand types are 'QDataStream'

I have a problem during serialization with a simple Managed Structure. My Class Header class MappySaver { public: MappySaver(); //structure struct Tile { public: int ID; int x,y,w,h; QRect rect; }; …
1
vote
1 answer

Read multiple floats from file in array

I want to read multiple float values from the file in which I already wrote using this: QDataStream &operator<<(QDataStream &out, const SomeClass &obj) { out << obj.maxX << obj.maxY << obj.minX << obj.minY; out << (int) obj.points.size(); …
konstantin_doncov
  • 2,725
  • 4
  • 40
  • 100
1
vote
0 answers

QDataStream not increasing position of QByteArray

When I write raw network bytes to a QDataStream object repeatedly, the QDataStream never increases the write position of the underlying QByteArray. Here's the code: QByteArray recvBuf; int bytePosition = 0; void init( ){ recvBuf = QByteArray(…
chris-kuhr
  • 355
  • 1
  • 5
  • 19
1
vote
1 answer

QDataStream operator << overloading for Abstract class

I want to overload << operator for abstract class as a virtual operator, I know how to overload the operator for simple class and code below is a sample. class NormalClass { public: int firstField() const; void…
saeed
  • 2,477
  • 2
  • 23
  • 40
1
vote
0 answers

Requesting model data from network

When in model methods rowCount() and columnCount() I try to retrieve data from server using QTcpSocket, the model calls these methods few times but not calls data() afterwards. The associated QTableView displays nothing. I checked with debugger and…
1
vote
3 answers

QTcpSocket::readAll() is empty

I am new to Qt and am in a bit of a struggle. I am trying to send a string from a client to a server using QTcpSocket. Client side: QByteArray block; QDataStream out(&block, QIODevice::WriteOnly); out.setVersion(QDataStream::Qt_4_0); out <<…