fix: 右键dock栏上的挂载图标,dock栏崩溃并且消失

对于无配置的Key,gSetting在调用gio函数的时候会崩溃,主要是g_settings_get_value内部断言造成的

Log: 无效gSetting配置导致程序崩溃
Bug: https://pms.uniontech.com/zentao/bug-view-65675.html
Change-Id: Ifc5af2535a4a19a27920f24392f53cdda4526d65
This commit is contained in:
吕伍军 2021-03-08 13:48:37 +08:00
parent a31da19cc6
commit f98c1f6e0d
2 changed files with 33 additions and 1 deletions

6
debian/control vendored
View File

@ -6,7 +6,8 @@ Build-Depends:
debhelper (>= 9), debhelper (>= 9),
cmake, cmake,
pkg-config, pkg-config,
qt5-default, qtbase5-dev,
qt5-qmake,
libglibmm-2.4-dev, libglibmm-2.4-dev,
doxygen, doxygen,
qttools5-dev-tools qttools5-dev-tools
@ -17,15 +18,18 @@ Package: libgio-qt
Architecture: any Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libglibmm-2.4-1v5 Depends: ${shlibs:Depends}, ${misc:Depends}, libglibmm-2.4-1v5
Description: Gio wrapper for Qt. Description: Gio wrapper for Qt.
A convenient way to bind gio with Qt5.
Package: libgio-qt-dev Package: libgio-qt-dev
Architecture: any Architecture: any
Section: libdevel Section: libdevel
Depends: libgio-qt, ${misc:Depends}, libglibmm-2.4-dev Depends: libgio-qt, ${misc:Depends}, libglibmm-2.4-dev
Description: Development package for libgio-qt. Description: Development package for libgio-qt.
A convenient way to bind gio with Qt5.
Package: libgio-qt-doc Package: libgio-qt-doc
Architecture: any Architecture: any
Section: doc Section: doc
Depends: ${misc:Depends} Depends: ${misc:Depends}
Description: Gio wrapper for Qt (documentation) Description: Gio wrapper for Qt (documentation)
A convenient way to bind gio with Qt5.

View File

@ -185,8 +185,33 @@ public:
GSettingsSchema* schema; GSettingsSchema* schema;
gulong signalHandlerId; 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 { QVariant value(GSettings* gsettings, const QString& key) const {
gchar* gkey = DGioPrivate::converToGChar(key.toUtf8()); gchar* gkey = DGioPrivate::converToGChar(key.toUtf8());
if(!inlcudeKey(gkey)) {
g_free(gkey);
return QVariant();
}
GVariant* variant = g_settings_get_value(gsettings, gkey); GVariant* variant = g_settings_get_value(gsettings, gkey);
QVariant qvalue = qconf_types_to_qvariant(variant); QVariant qvalue = qconf_types_to_qvariant(variant);
g_variant_unref(variant); g_variant_unref(variant);
@ -198,6 +223,9 @@ public:
bool trySet(const QString& key, const QVariant& value) bool trySet(const QString& key, const QVariant& value)
{ {
const gchar* gkey = key.toUtf8().constData(); const gchar* gkey = key.toUtf8().constData();
if(!inlcudeKey(gkey)) return false;
bool success = false; bool success = false;
/* fetch current value to find out the exact type */ /* fetch current value to find out the exact type */