From a825e1bd74246dc97dde3f48b1d9ead7a214b744 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Mon, 8 Feb 2021 21:32:10 +0000 Subject: Avoid KJob::exec() in DolphinView This commit replaces an error-prone usage of KIO::StatJob::exec() in DolphinView with the recommended KIO::StatJob::start(). The containing method DolphinView::statusBarText() is changed to be a method without return value: requestStatusBarText() The new status bar text is instead returned through a new setStatusBarText() signal that will be emitted asynchronously if necessary. The calling code that deals with status bar text is refactored to correctly work despite the new asynchronicity. The helper method calculateItemCount() is moved into requestStatusBarText() and some other code from requestStatusBarText() is moved into a new helper method emitStatusBarText(). The documentation of KIO::KJob::exec() explains why it should be avoided. A reproducible crash is the reason for this commit. --- src/dolphinpart.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/dolphinpart.cpp') diff --git a/src/dolphinpart.cpp b/src/dolphinpart.cpp index 37ffe9070..935602540 100644 --- a/src/dolphinpart.cpp +++ b/src/dolphinpart.cpp @@ -85,6 +85,10 @@ DolphinPart::DolphinPart(QWidget* parentWidget, QObject* parent, this, &DolphinPart::slotItemActivated); connect(m_view, &DolphinView::itemsActivated, this, &DolphinPart::slotItemsActivated); + connect(m_view, &DolphinView::statusBarTextChanged, this, [this](const QString &text) { + const QString escapedText = Qt::convertFromPlainText(text); + Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("%1").arg(escapedText)); + }); connect(m_view, &DolphinView::tabRequested, this, &DolphinPart::createNewWindow); connect(m_view, &DolphinView::requestContextMenu, @@ -597,8 +601,7 @@ void DolphinPart::updateNewMenu() void DolphinPart::updateStatusBar() { - const QString escapedText = Qt::convertFromPlainText(m_view->statusBarText()); - Q_EMIT ReadOnlyPart::setStatusBarText(QStringLiteral("%1").arg(escapedText)); + m_view->requestStatusBarText(); } void DolphinPart::updateProgress(int percent) -- cgit v1.3