[frameworks/kio] src/widgets: WidgetsAskUserActionHandler: show the SSL error dialog on the GUI thread

Méven Car <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit dd40b4c0902dbcb470872d878d3387ab70b4bf62 by Méven Car, on behalf of Shouvik Kar.
Committed on 18/07/2026 at 09:22.
Pushed by meven into branch 'master'.

WidgetsAskUserActionHandler: show the SSL error dialog on the GUI thread

askIgnoreSslErrors() can be called from a non-GUI thread (e.g. the weather
ion runs its KIO jobs on a worker thread), where it constructed the
KMessageDialog off the GUI thread and crashed while painting it.

Marshal the dialog onto the GUI thread with QMetaObject::invokeMethod(qGuiApp,
...), like every other handler in this class already does.

BUG: 519614

M  +22   -20   src/widgets/widgetsaskuseractionhandler.cpp

https://invent.kde.org/frameworks/kio/-/commit/dd40b4c0902dbcb470872d878d3387ab70b4bf62

diff --git a/src/widgets/widgetsaskuseractionhandler.cpp b/src/widgets/widgetsaskuseractionhandler.cpp
index db8d895a9d..85aedca460 100644
--- a/src/widgets/widgetsaskuseractionhandler.cpp
+++ b/src/widgets/widgetsaskuseractionhandler.cpp
@@ -502,32 +502,34 @@ void KIO::WidgetsAskUserActionHandler::setWindow(QWidget *window)
 
 void KIO::WidgetsAskUserActionHandler::askIgnoreSslErrors(const QVariantMap &sslErrorData, QWidget *parent)
 {
-    QWidget *parentWidget = d->getParentWidget(parent);
+    QMetaObject::invokeMethod(qGuiApp, [=, this] {
+        QWidget *parentWidget = d->getParentWidget(parent);
 
-    QString message = i18n("The server failed the authenticity check (%1).\n\n", sslErrorData[QLatin1String("hostname")].toString());
+        QString message = i18n("The server failed the authenticity check (%1).\n\n", sslErrorData[QLatin1String("hostname")].toString());
 
-    message += sslErrorData[QLatin1String("sslError")].toString();
+        message += sslErrorData[QLatin1String("sslError")].toString();
 
-    auto *dialog = new KMessageDialog(KMessageDialog::WarningTwoActionsCancel, message, parentWidget);
+        auto *dialog = new KMessageDialog(KMessageDialog::WarningTwoActionsCancel, message, parentWidget);
 
-    dialog->setAttribute(Qt::WA_DeleteOnClose);
-    dialog->setCaption(i18n("Server Authentication"));
-    dialog->setIcon(QIcon{});
-    dialog->setButtons(KGuiItem{i18n("&Details"), QStringLiteral("documentinfo")}, KStandardGuiItem::cont(), KStandardGuiItem::cancel());
+        dialog->setAttribute(Qt::WA_DeleteOnClose);
+        dialog->setCaption(i18n("Server Authentication"));
+        dialog->setIcon(QIcon{});
+        dialog->setButtons(KGuiItem{i18n("&Details"), QStringLiteral("documentinfo")}, KStandardGuiItem::cont(), KStandardGuiItem::cancel());
+
+        connect(dialog, &KMessageDialog::finished, this, [this, parentWidget, sslErrorData](int result) {
+            if (result == KMessageDialog::PrimaryAction) {
+                showSslDetails(sslErrorData, parentWidget);
+            } else if (result == KMessageDialog::SecondaryAction) {
+                // continue();
+                Q_EMIT askIgnoreSslErrorsResult(1);
+            } else if (result == KMessageDialog::Cancel) {
+                // cancel();
+                Q_EMIT askIgnoreSslErrorsResult(0);
+            }
+        });
 
-    connect(dialog, &KMessageDialog::finished, this, [this, parentWidget, sslErrorData](int result) {
-        if (result == KMessageDialog::PrimaryAction) {
-            showSslDetails(sslErrorData, parentWidget);
-        } else if (result == KMessageDialog::SecondaryAction) {
-            // continue();
-            Q_EMIT askIgnoreSslErrorsResult(1);
-        } else if (result == KMessageDialog::Cancel) {
-            // cancel();
-            Q_EMIT askIgnoreSslErrorsResult(0);
-        }
+        dialog->show();
     });
-
-    dialog->show();
 }
 
 void KIO::WidgetsAskUserActionHandler::showSslDetails(const QVariantMap &sslErrorData, QWidget *parentWidget)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.