3

QByteArray is serialized in different formats on the file system if the different version of Qt library is used (say 4.5.2 against 4.7.1). I use the QSettings in my application to store the some binary data in the .ini file. Now application is migrated to Qt 4.7.1 and if updated version of app reads (using the QSettings value method) the resulted QByteArray is not equal to the serialized by previous version of app.

Possible solution:

  • maintain the version of Qt used by app (I store the app version in the settings)

  • implement the own format for QSettings (wrapper for ini format) with own ReadFunc and WriteFunc.

  • read/write QByteArray settings using the QDataStream within setVersion using the maintained Qt version.

Any more simple solutions?

NG_
  • 6,895
  • 7
  • 45
  • 67
MedBrother
  • 31
  • 2
  • Hard coding a version in QDataStream seems pretty simple. It's certainly simpler than the first two options. – Arnold Spence May 13 '11 at 14:38
  • If it's purely the Qt version that is changing I would go for Qt's [own versioning](http://doc.trolltech.com/latest/qdatastream.html#versioning), as I think your last option suggests. – Bart May 13 '11 at 14:39

1 Answers1

2

QDataStream's setVersion is the simplest and quickest way.

http://doc.qt.io/qt-4.8/qdatastream.html#setVersion

and for future reference the Qt5 version:

http://doc.qt.io/qt-5.5/qdatastream.html#setVersion

Phil Hannent
  • 12,047
  • 17
  • 71
  • 118