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.

103 questions
6
votes
2 answers

How to serialize a QAbstractItemModel into QDataStream?

I've set up a QAbstractItemModel and filled that with data. My QTreeView widget displays every data in that model properly. Now, I would like to store that model serialized in a binary file (and later of cource load that binary file back into a…
6
votes
1 answer

Using Qdatastream read data from socket and write into file

I need to receive binary data(reading float) through a QTcpSocket and write them into Qfile using QDatastream. But I am having some problems with QDataStream. As follows, I can only achieve it using this way : QDataStream…
Chen Xu
  • 332
  • 1
  • 4
  • 13
4
votes
2 answers

How to Save/Load a custom struct into a binary file using QDataStream in Qt?

I am going to save a struct in a binary file and load it later on. I found that one way is to use QVariant. Here is a simplified Qt Widget Application example that I have created. But when I run it the binary file remains empty. Could you please…
Keyvan
  • 73
  • 7
4
votes
3 answers

Append a QByteArray to QDataStream?

I have to populate a QByteArray with different data. So I'm using the QDataStream. QByteArray buffer; QDataStream stream(&buffer, QIODevice::WriteOnly); qint8 dataHex= 0x04; qint8 dataChar = 'V'; stream << dataHex<< dataChar; qDebug() <<…
TheMeaningfulEngineer
  • 13,149
  • 20
  • 73
  • 132
4
votes
1 answer

How to serialize custom objects

I have a problem trying to serialize on disk my objects. This is a simplified scenario: I have ObjectA providing its own serialization operators. They work since I can save/load data to file. Next I have ObjectB containing ObjectA as data member.…
bullet
  • 57
  • 7
3
votes
2 answers

How do I properly serialize and deserialize a QList class in QT using QDatastream?

I am trying to serialize a custom class Layer* and read it back using QDataStream. Now, Layer is an abstract class with virtual method which is inherited by different kinds of layers: RasterLayer, TextLayer, AdjustmentLayer etc. I have a…
twodee
  • 571
  • 4
  • 23
3
votes
1 answer

How to open a bin file in Python using QDataStream

I've got a bin file that was encoded in an application that I need to get access to and convert to a csv file. I've been given the documentation, but am not sure how to access the contents of this file in Python. Here are some of the details about…
Michael Bawol
  • 353
  • 2
  • 9
3
votes
1 answer

copying char to QbyteArray with datastream contains some extra bytes

Overview of problem: OS : Ubuntu I am using qt utility to receive video data from remote machine( remote machine is using gstreamer to send live data) and write that data to port say 5000. Port 5000 is already bind to another gstreamer utility.…
samprat
  • 1,940
  • 6
  • 30
  • 64
3
votes
1 answer

How to compare two parsed files and append the difference to the first?

Suppose I have two .dat files; one on my computer and the other one on the other side of the earth - with data constantly being serialized into them through a QDataStream. The data is parsed the same way – first some sort of ID and then an object…
Quoi
  • 135
  • 1
  • 8
3
votes
2 answers

How to send data from server to client as QByteArray/QDataStream

In the fortuneserver sample of Qt, a QString is sent by the method sendFortune(). Therefore one QString is selected from the QStringList fortunes: QByteArray block; QDataStream out(&block,…
3ef9g
  • 661
  • 1
  • 8
  • 16
2
votes
1 answer

Disable std::optional's forwarding constructor

I've extended QDataStream with a template conversion operator so that the datastream loads from itself and converts to any supported type, as such: class ConvertibleQDataStream : public QDataStream { public: using QDataStream::QDataStream; …
Unimportant
  • 1,974
  • 12
  • 17
2
votes
1 answer

QDataStream empty after call of QDataStream::writeRawData

I have a rather odd problem, using QDataStream, or at least it is odd to me, because I don't understand the behavior at all. Of course my problem is from a big project, but I managed to reproduce that odd behavior with a minimal example, which I'll…
Lilo
  • 331
  • 2
  • 13
2
votes
1 answer

How to know that QDataStream cannot deserialize something?

Please, consider the following code fragment from the QDataStream documentation: QFile file("file.dat"); file.open(QIODevice::ReadOnly); QDataStream in(&file); // read the data serialized from the file QString str; qint32 a; in >> str >> a; …
uni
  • 397
  • 1
  • 6
  • 15
2
votes
1 answer

Reading from QDataStream to QVector: application crashes with SIGABRT signal

A crash with this message: The inferior stopped because it received a signal from the operating system. Signal name : SIGABRT Signal meaning : Aborted happens at this line of code: // data is QByteArray ... QByteArray pos0 = data.mid( index,…
user3405291
  • 5,371
  • 3
  • 32
  • 81
2
votes
1 answer

What is the proper way to exchange data between QTcpSocket and python socket?

I am sending .jpg images from Qt client to python server. Qt client sends as follows: void Sender::sendToServer(QByteArray imageData) { QDataStream stream(serverSocket); int t = imageData.size(); stream << t; stream << imageData; …
Bobur
  • 455
  • 5
  • 17
1
2 3 4 5 6 7