diff options
author | Kai Koehne <kai.koehne@qt.io> | 2018-07-23 11:49:19 +0200 |
---|---|---|
committer | Kai Koehne <kai.koehne@qt.io> | 2018-07-28 14:43:40 +0000 |
commit | bd0279c4173eb627d432d9a05411bbc725240d4e (patch) | |
tree | 4bcd3bb9f3dd1f8882fc71fd2ffa2dda3ec37891 /src/corelib/io | |
parent | 01d2f35b6988edacc741b358703d16d4cd8c199a (diff) |
Logging: Accept .ini files written by QSettings
For keys, QSettings escapes all characters outside of [-a-zA-Z0-9_.]
by using percent encoding, and changes '/' to '\'. That is,
settings.setValue("qt.*", true)
will be written to an .ini file as
qt.%2A=true
This means that QSettings can not be used to write general-purpose
qtlogging.ini files. Fix this by applying the reverse transformation
method from QSettings when reading in the .ini file.
[ChangeLog][Logging] Qt will now accept qtlogging.ini files
written by QSettings.
Task-number: QTBUG-69548
Change-Id: I55b7a8b433291268dc6855901f72b1c04f8ee6d3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index cd97268d71..9792d956cc 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -46,6 +46,11 @@ #include <QtCore/qdir.h> #include <QtCore/qcoreapplication.h> +#if QT_CONFIG(settings) +#include <QtCore/qsettings.h> +#include <QtCore/private/qsettings_p.h> +#endif + // We can't use the default macros because this would lead to recursion. // Instead let's define our own one that unconditionally logs... #define debugMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").debug @@ -230,7 +235,14 @@ void QLoggingSettingsParser::parseNextLine(QStringRef line) int equalPos = line.indexOf(QLatin1Char('=')); if (equalPos != -1) { if (line.lastIndexOf(QLatin1Char('=')) == equalPos) { - const auto pattern = line.left(equalPos).trimmed(); + const auto key = line.left(equalPos).trimmed(); +#if QT_CONFIG(settings) + QString tmp; + QSettingsPrivate::iniUnescapedKey(key.toUtf8(), 0, key.length(), tmp); + QStringRef pattern = QStringRef(&tmp, 0, tmp.length()); +#else + QStringRef pattern = key; +#endif const auto valueStr = line.mid(equalPos + 1).trimmed(); int value = -1; if (valueStr == QLatin1String("true")) |