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
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,…
Megidd
  • 7,089
  • 6
  • 65
  • 142
2
votes
2 answers

Issues with QDataStream using QString and QByteArray

QByteArray ba; QDataStream ds(&ba,QIODevice::WriteOnly); ds<
Peter Zhang
  • 61
  • 1
  • 8
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
  • 545
  • 1
  • 6
  • 21
2
votes
1 answer

Why do I need reinterpret_cast from `long &` to `int &` where both are 32-bit (Windows LLP64)?

I am working with Qt in a cross-platform environment. And we are running into the following problem: On Windows, both int and long int are 32-bit integers; on 64-bit MacOS and Linux, int is 32-bit and long int is 64 bit (see…
Tilman Vogel
  • 9,337
  • 4
  • 33
  • 32
2
votes
1 answer

Deserialization of raw data using QDataStream

I have data which comes from tcp socket as raw data (i have a specified format) and then create an object based on that data. Format is like this: 24 bytes of header [size of data and some other info] and then amount of data specified in header. I…
Voider
  • 83
  • 9
2
votes
1 answer

QDataStream custom writing - one vs multiple lines;

I'll write a custom operator for my struct, and I'm wondering if there is any difference in performance between the two: QDataStream &operator<<(QDataStream &out, const Event &event) { out << event.a; out << event.b; out <<…
mathiasfk
  • 1,278
  • 1
  • 19
  • 38
2
votes
1 answer

QPixmap.loadFromData() does not load image from QByteArray

I'm creating a socket-based program to send a screenshot from one user to another user. I need to convert a screenshot to a byte array before sending. After I convert my screenshot to a QByteArray I insert 4 bytes to the beginning of the array to…
amir
  • 45
  • 2
  • 5
2
votes
1 answer

read / write on byte array by QDataStream

i have byte image array i want to write this byte array to another byte array with add some another value on second byte array , i'm using this code but i think something is wrong QByteArray byteArray; QDataStream…
NetProjects Ir
  • 61
  • 2
  • 10
2
votes
2 answers

Count number of bytes written to QDataStream in Qt5

In my code I am preparing some data for sending over a network using QDataStream. In the middle of the preparations I would like to know exactly how many bytes that were prepared at that point. How can I do that? Example: int myFunc(QDataStream…
Mr. Developerdude
  • 9,118
  • 10
  • 57
  • 95
2
votes
1 answer

Reading and writing QByteArray to QDataSteam

I have encountered a problem in sending a QByteArray through QDataStream. I have created a class for storing serialized message to send it through socket, class looks like this: #ifndef SERIALIZEDMESSAGE_H #define SERIALIZEDMESSAGE_H #include…
CucumisSativus
  • 310
  • 3
  • 11
2
votes
1 answer

“plain/text” encodedData and QDataStream to readable QString

I'd like to convert the following snippet to use "plain/text" mimetype without relying on QTextStream bool DragDropListModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) { …
vooorka
  • 31
  • 4
2
votes
1 answer

QDataStream serialize pointer

I am implementing a little interface with Qt. In the step I am currently working on, I have Scores (custom class) I can move on Docks (again, custom class) that can hold only one Score. I inspired myself (a lot) with this example: Fridge magnets. In…
2
votes
2 answers

Datastream Qt to standard c++ code

I created function Qt to read in a binary file, and it works. [code] if (fileLoad.open(QIODevice::ReadOnly)) { QDataStream in(&fileLoad); quint8 Variable_8bits; quint16 Variable_16bits; quint32 Variable_32bits; in >>…
2lights
  • 41
  • 2
1
vote
0 answers

Default byte order of QDataStream

Default byte order of QDataStream is BigEndian, according to its documentation. AFAIK this means that written data on a little-endian platform is converted from little to big and read data is converted from big to little. Most platforms supported by…
Silicomancer
  • 8,604
  • 10
  • 63
  • 130
1
vote
1 answer

QBtyeArray QDataStream qCompress to file adding extra leading bytes

Qt/C++ program has a function which writes an objects data (_token) to a file as follows: QFile f( _tokenFile); if (!f.open( QIODevice::WriteOnly)) { qDebug() << "Unable to open token file for writing" << f.errorString(); …
TenG
  • 3,843
  • 2
  • 25
  • 42