QWinRegistryKey: Fix how we handle the default value, take 2
It seems the value name correction is not needed at all, and we must not do such correction. Amends commit 738e05a55a4047268553eea6b9f4809d42181eef Task-number: QTBUG-107794 Change-Id: I903a762aafab4b55275beb8438e6769285821567 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
19857fda75
commit
32774f13d9
@ -38,13 +38,14 @@ void QWinRegistryKey::close()
|
|||||||
|
|
||||||
QVariant QWinRegistryKey::value(QStringView subKey) const
|
QVariant QWinRegistryKey::value(QStringView subKey) const
|
||||||
{
|
{
|
||||||
|
// NOTE: Empty value name is allowed in Windows registry, it means the default
|
||||||
|
// or unnamed value of a key, you can read/write/delete such value normally.
|
||||||
|
|
||||||
if (!isValid())
|
if (!isValid())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (subKey.isEmpty())
|
// Use nullptr when we need to access the default value.
|
||||||
subKey = u"Default";
|
const auto subKeyC = subKey.isEmpty() ? nullptr : reinterpret_cast<const wchar_t *>(subKey.utf16());
|
||||||
|
|
||||||
auto subKeyC = reinterpret_cast<const wchar_t *>(subKey.utf16());
|
|
||||||
|
|
||||||
// Get the size and type of the value.
|
// Get the size and type of the value.
|
||||||
DWORD dataType = REG_NONE;
|
DWORD dataType = REG_NONE;
|
||||||
|
@ -20,7 +20,7 @@ static const QPair<QStringView, quint32> TEST_DWORD = qMakePair(u"dword", 123);
|
|||||||
static const QPair<QStringView, quint64> TEST_QWORD = qMakePair(u"qword", 456);
|
static const QPair<QStringView, quint64> TEST_QWORD = qMakePair(u"qword", 456);
|
||||||
static const QPair<QStringView, QByteArray> TEST_BINARY = qMakePair(u"binary", "binary\0"_ba);
|
static const QPair<QStringView, QByteArray> TEST_BINARY = qMakePair(u"binary", "binary\0"_ba);
|
||||||
static const QPair<QStringView, QVariant> TEST_NOT_EXIST = qMakePair(u"not_exist", QVariant());
|
static const QPair<QStringView, QVariant> TEST_NOT_EXIST = qMakePair(u"not_exist", QVariant());
|
||||||
static const QPair<QStringView, QVariant> TEST_DEFAULT = qMakePair(u"Default", u"default"_s);
|
static const QPair<QStringView, QVariant> TEST_DEFAULT = qMakePair(u"", u"default"_s);
|
||||||
|
|
||||||
[[nodiscard]] static inline bool write(const HKEY key, const QStringView name, const QVariant &value)
|
[[nodiscard]] static inline bool write(const HKEY key, const QStringView name, const QVariant &value)
|
||||||
{
|
{
|
||||||
@ -216,12 +216,6 @@ void tst_qwinregistrykey::qwinregistrykey()
|
|||||||
QCOMPARE(value.value_or(QString()), TEST_DEFAULT.second);
|
QCOMPARE(value.value_or(QString()), TEST_DEFAULT.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
const auto value = registry.value<QString>(L"");
|
|
||||||
QVERIFY(value.has_value());
|
|
||||||
QCOMPARE(value.value_or(QString()), TEST_DEFAULT.second);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
const QString value = registry.stringValue(TEST_STRING.first);
|
const QString value = registry.stringValue(TEST_STRING.first);
|
||||||
QVERIFY(!value.isEmpty());
|
QVERIFY(!value.isEmpty());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user