From 588abbf1b6994245d987c0d07c2b074cb76fc034 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Sun, 3 Jun 2018 13:08:51 +0200 Subject: [PATCH] Fix crash in PlacesItem::setUrl() 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 | 4 +--- src/panels/places/placesitemsignalhandler.cpp | 7 +++++++ src/panels/places/placesitemsignalhandler.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/panels/places/placesitem.cpp b/src/panels/places/placesitem.cpp index ee168e4a30..10b87086cf 100644 --- a/src/panels/places/placesitem.cpp +++ b/src/panels/places/placesitem.cpp @@ -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); diff --git a/src/panels/places/placesitemsignalhandler.cpp b/src/panels/places/placesitemsignalhandler.cpp index c85c8336ee..b313f838f3 100644 --- a/src/panels/places/placesitemsignalhandler.cpp +++ b/src/panels/places/placesitemsignalhandler.cpp @@ -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")); + } +} + diff --git a/src/panels/places/placesitemsignalhandler.h b/src/panels/places/placesitemsignalhandler.h index 6158d71806..1d0cf9ccda 100644 --- a/src/panels/places/placesitemsignalhandler.h +++ b/src/panels/places/placesitemsignalhandler.h @@ -58,6 +58,8 @@ public slots: void onTearDownRequested(const QString& udi); + void onTrashEmptinessChanged(bool isTrashEmpty); + signals: void tearDownExternallyRequested(const QString& udi);