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
This commit is contained in:
Elvis Angelaccio 2018-06-03 13:08:51 +02:00
parent 45e9fc22d9
commit 588abbf1b6
3 changed files with 10 additions and 3 deletions

View 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);

View 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"));
}
}

View file

@ -58,6 +58,8 @@ public slots:
void onTearDownRequested(const QString& udi);
void onTrashEmptinessChanged(bool isTrashEmpty);
signals:
void tearDownExternallyRequested(const QString& udi);