From f98c1f6e0d4e4340f2a605b2eb2bad4edb791563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E4=BC=8D=E5=86=9B?= Date: Mon, 8 Mar 2021 13:48:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=B3=E9=94=AEdock=E6=A0=8F=E4=B8=8A?= =?UTF-8?q?=E7=9A=84=E6=8C=82=E8=BD=BD=E5=9B=BE=E6=A0=87=EF=BC=8Cdock?= =?UTF-8?q?=E6=A0=8F=E5=B4=A9=E6=BA=83=E5=B9=B6=E4=B8=94=E6=B6=88=E5=A4=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对于无配置的Key,gSetting在调用gio函数的时候会崩溃,主要是g_settings_get_value内部断言造成的 Log: 无效gSetting配置导致程序崩溃 Bug: https://pms.uniontech.com/zentao/bug-view-65675.html Change-Id: Ifc5af2535a4a19a27920f24392f53cdda4526d65 --- debian/control | 6 +++++- gio-qt/source/dgiosettings.cpp | 28 ++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index 16235c2..259b3ad 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,8 @@ Build-Depends: debhelper (>= 9), cmake, pkg-config, - qt5-default, + qtbase5-dev, + qt5-qmake, libglibmm-2.4-dev, doxygen, qttools5-dev-tools @@ -17,15 +18,18 @@ Package: libgio-qt Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends}, libglibmm-2.4-1v5 Description: Gio wrapper for Qt. + A convenient way to bind gio with Qt5. Package: libgio-qt-dev Architecture: any Section: libdevel Depends: libgio-qt, ${misc:Depends}, libglibmm-2.4-dev Description: Development package for libgio-qt. + A convenient way to bind gio with Qt5. Package: libgio-qt-doc Architecture: any Section: doc Depends: ${misc:Depends} Description: Gio wrapper for Qt (documentation) + A convenient way to bind gio with Qt5. diff --git a/gio-qt/source/dgiosettings.cpp b/gio-qt/source/dgiosettings.cpp index 4abee04..13d6e2b 100644 --- a/gio-qt/source/dgiosettings.cpp +++ b/gio-qt/source/dgiosettings.cpp @@ -185,8 +185,33 @@ public: GSettingsSchema* schema; gulong signalHandlerId; + bool strvHasString (gchar **haystack, const gchar *needle) const { + if (needle == nullptr) return false; + + for (guint n = 0; haystack != NULL && haystack[n] != NULL; n++) { + if (g_strcmp0 (haystack[n], needle) == 0) + return true; + } + + return false; + } + + bool inlcudeKey(const gchar* gkey) const { + gchar **allKeys = g_settings_list_keys(settings); + bool ret = strvHasString (allKeys, gkey); + g_strfreev (allKeys); + + return ret; + } + QVariant value(GSettings* gsettings, const QString& key) const { gchar* gkey = DGioPrivate::converToGChar(key.toUtf8()); + + if(!inlcudeKey(gkey)) { + g_free(gkey); + return QVariant(); + } + GVariant* variant = g_settings_get_value(gsettings, gkey); QVariant qvalue = qconf_types_to_qvariant(variant); g_variant_unref(variant); @@ -198,6 +223,9 @@ public: bool trySet(const QString& key, const QVariant& value) { const gchar* gkey = key.toUtf8().constData(); + + if(!inlcudeKey(gkey)) return false; + bool success = false; /* fetch current value to find out the exact type */