Concern about QDataStream and versions

  • It seems that setting the version for QDataStream seems essential when writing/reading complex types. Does the documentation mean complex types that are part of the Qt library that can be streamed (ie. QDateTime), or does this include even classes I would make and overload operators for use in QDataStream? I hope it's the former, because it makes me wonder if the stream would be streaming any other data than what I tell it to, seeing as I'm trying to implement a network specification. Yes, I am aware using the stream operators to input/output strings will add a 32-bit length value beforehand, which is why I use write/readRawData in that case, but the stream operator for integer types

  • Lifetime Qt Champion


    The idea is by setting the version you ensure that you are always using the same binary format independently of the Qt version you use. The class you are streaming is not important in that aspect. Whether it is a Qt class or you own, you will just use QDataStream.

    Hope it helps

  • So it is otherwise okay to not touch the version?

  • Lifetime Qt Champion

    Yes, but like it's written, look carefully at your use case before choosing what you will use

  • I'm still pretty confused. Perhaps I'll look at the source code to see what's affected. The documentation just doesn't seem clear to me.

    EDIT: took a look at qdatastream.cpp and the only conditional involving the version is the floating point precision for Qt >= 4.6. If that's the only one used, I fail to see how the 15 revisions so far reflect anything changed.

    EDIT 2: I wrote a test program to see any differences between the output of different formats and I don't see any output difference when outputting the same test data from versions 1 through 15

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.