From 5f70b8114aea9b4ee1c7b1b68149d043c48efcb5 Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Fri, 22 Mar 2024 18:19:19 +0800 Subject: [PATCH] fix: lossing value when save DConfig Blocking caller until it's finished, otherwise it maybe lose value when application is quit early. --- src/dconfig.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/dconfig.cpp b/src/dconfig.cpp index 957f7465..ef7325af 100644 --- a/src/dconfig.cpp +++ b/src/dconfig.cpp @@ -398,7 +398,8 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend auto reply = config->isDefaultValue(key); reply.waitForFinished(); if (reply.isError()) { - qWarning() << "Wrong when calling `isDefaultValue`, key:" << key << ", error message:" << reply.error().message(); + qWarning() << "Failed to call `isDefaultValue`, key:" << key + << ", error message:" << reply.error().message(); return false; } return reply.value(); @@ -406,12 +407,20 @@ class Q_DECL_HIDDEN DBusBackend : public DConfigBackend virtual void setValue(const QString &key, const QVariant &value) override { - config->setValue(key, QDBusVariant(value)); + auto reply = config->setValue(key, QDBusVariant(value)); + reply.waitForFinished(); + if (reply.isError()) + qCWarning(cfLog) << "Failed to setValue for the key:" << key + << ", error message:" << reply.error(); } virtual void reset(const QString &key) override { - config->reset(key); + auto reply = config->reset(key); + reply.waitForFinished(); + if (reply.isError()) + qCWarning(cfLog) << "Failed to reset for the key:" << key + << ", error message:" << reply.error(); } virtual QString name() const override