Working with QDataStream and QTcpSocket

The missing piece of the SDK is MesssageUtils. It deserves a dedicated section because it covers two major topics: serialization and QDataStream transactions.

We will start with the serialization. We already know that Message stores only an opaque QByteArray data member. As a consequence, the desired data has to be serialized as QByteArray before being passed to Message.

If we take the example of a JobRequest object, it is not directly sent. We first put it in a generic Message object with the appropriate Message type. The following diagram summarizes the sequence of actions to be done:

The JobRequest ...

Get Mastering Qt 5 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.