]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix crash in PlacesItem::setUrl()
authorElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 3 Jun 2018 11:08:51 +0000 (13:08 +0200)
committerElvis Angelaccio <elvis.angelaccio@kde.org>
Sun, 3 Jun 2018 11:08:51 +0000 (13:08 +0200)
Connections to lambda slots without context/receiver argument can lead
to crashes, because if the receiver is deleted Qt won't delete the connection
as it normally would when the receiver is specified.

This patch moves the slot from the lambda in PlacesItem (which is not a QObject)
to PlacesItemSignalHandler. This fixes the `dolphinmainwindowtest` crash
we currently have on master, and should also fix bug #394507 which has
the very same stacktrace.

BUG: 394507
FIXED-IN: 18.04.2

src/panels/places/placesitem.cpp
src/panels/places/placesitemsignalhandler.cpp
src/panels/places/placesitemsignalhandler.h

index ee168e4a309d39e94e45cd12baa1d33d68845c31..10b87086cf94a63fd7c0138ec025553f2f516923 100644 (file)
@@ -61,9 +61,7 @@ void PlacesItem::setUrl(const QUrl &url)
     if (dataValue("url").toUrl() != url) {
         delete m_trashDirLister;
         if (url.scheme() == QLatin1String("trash")) {
-            QObject::connect(&Trash::instance(), &Trash::emptinessChanged, [this](bool isTrashEmpty){
-                setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full"));
-            });
+            QObject::connect(&Trash::instance(), &Trash::emptinessChanged, m_signalHandler.data(), &PlacesItemSignalHandler::onTrashEmptinessChanged);
         }
 
         setDataValue("url", url);
index c85c8336ee492c451c9538c6ba4a19908e15c8d7..b313f838f33de1952404cb46e6a6a9c27211f13e 100644 (file)
@@ -51,3 +51,10 @@ void PlacesItemSignalHandler::onTearDownRequested(const QString& udi)
     }
 }
 
+void PlacesItemSignalHandler::onTrashEmptinessChanged(bool isTrashEmpty)
+{
+    if (m_item) {
+        m_item->setIcon(isTrashEmpty ? QStringLiteral("user-trash") : QStringLiteral("user-trash-full"));
+    }
+}
+
index 6158d7180672e6024758550cf7050b53c2f1182c..1d0cf9ccdac5a06dbccbc5c416cab000c2d2bcb2 100644 (file)
@@ -58,6 +58,8 @@ public slots:
 
     void onTearDownRequested(const QString& udi);
 
+    void onTrashEmptinessChanged(bool isTrashEmpty);
+
 signals:
     void tearDownExternallyRequested(const QString& udi);