Fix handling of DateTime values in QSettings
Since 5.6.0, Qt's serialization of QDateTime in QSettings files has had special-case handling to use a newer QDataStream version than the one QSettings uses for most other types. This was handled in the serialization and parsing, but not taken into account in the code that turned binary data into content suitable for saving to an ini file. In Qt 5 this caused no problem when no iniCodec was set on the QSettings object but Qt 6 now uses UTF-8 as (in effect) codec on every QSettings object. This lead to the binary data encoding QDateTime being encoded as if it were Unicode, instead of using \x tokens where suitable. This lead to an unintended incompatible change in how QSettings stores QDateTime values: Qt 6 was still able to read Qt 5's values, but Qt 5 was unable to read Qt 6's settings files (unless it sets its iniCodec to UTF-8, which works round the problem). The code to convert raw binary data to ini-file-friendly value texts had a special case for ByteArray and Variant values, to ignore the codec and use \x tokens: when support for QDateTime was split from Variant, it gained a DateTime prefix in the parsing code that wasn't included in this special handling. So add that now. The resulting DateTime values now match Qt 5 so are readable by it and by Qt 6 (including versions prior to this change); and the code to read a DateTime can still read what earlier Qt 6 versions have been writing. It is likely a Qt 5 QSettings with an iniCodec other than UTF-8 may have problems with the result, but that was already true. This amends commit 73b8cd879cd723fbcce42e63f21cc864d13cb91e Fixes: QTBUG-102334 Pick-to: 6.2 6.3 5.15 Change-Id: Icc44a33db3dcc6400144bc001710b400ee883c90 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
parent
bead1894b7
commit
6c5dac1685
@ -633,7 +633,8 @@ void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result)
|
||||
bool needsQuotes = false;
|
||||
bool escapeNextIfDigit = false;
|
||||
bool useCodec = !str.startsWith("@ByteArray("_L1)
|
||||
&& !str.startsWith("@Variant("_L1);
|
||||
&& !str.startsWith("@Variant("_L1)
|
||||
&& !str.startsWith("@DateTime("_L1);
|
||||
|
||||
qsizetype i;
|
||||
qsizetype startPos = result.size();
|
||||
|
Loading…
x
Reference in New Issue
Block a user