From f7120daa2e5c3bf02ade6b68606572a189de0678 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 16 May 2024 09:36:41 +0200 Subject: [PATCH] FancyLineEdit: Make sure to not leave any threads hanging around Add them to the global future synchronizer, so they are canceled and waited for before deleting any plugin instances. Change-Id: Iec78b7566905815c4d2b4cc7410d10b2da16c7b7 Reviewed-by: Jarek Kobus --- src/libs/utils/fancylineedit.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/libs/utils/fancylineedit.cpp b/src/libs/utils/fancylineedit.cpp index 44a94236085..d57505a70b7 100644 --- a/src/libs/utils/fancylineedit.cpp +++ b/src/libs/utils/fancylineedit.cpp @@ -5,6 +5,7 @@ #include "camelcasecursor.h" #include "execmenu.h" +#include "futuresynchronizer.h" #include "historycompleter.h" #include "hostosinfo.h" #include "icon.h" @@ -98,6 +99,7 @@ class FancyLineEditPrivate : public QObject { public: explicit FancyLineEditPrivate(FancyLineEdit *parent); + ~FancyLineEditPrivate(); bool eventFilter(QObject *obj, QEvent *event) override; @@ -163,6 +165,12 @@ FancyLineEditPrivate::FancyLineEditPrivate(FancyLineEdit *parent) } } +FancyLineEditPrivate::~FancyLineEditPrivate() +{ + if (m_validatorWatcher) + m_validatorWatcher->cancel(); +} + bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event) { int buttonIndex = -1; @@ -446,12 +454,27 @@ void FancyLineEdit::setFiltering(bool on) } } +/*! + Set a synchronous or asynchronous validation function \a fn. + Asynchronous validation functions can continue to run after destruction of the + FancyLineEdit instance. During shutdown asynchronous validation functions can continue + to run until before the plugin instances are deleted (at that point the plugin manager + waits for them to finish before continuing). + + \sa defaultValidationFunction() + */ void FancyLineEdit::setValidationFunction(const FancyLineEdit::ValidationFunction &fn) { d->m_validationFunction = fn; validate(); } +/*! + Returns the default validation function, which synchonously executes the line edit's + validator. + + \sa setValidationFunction() +*/ FancyLineEdit::ValidationFunction FancyLineEdit::defaultValidationFunction() { return &FancyLineEdit::validateWithValidator; @@ -581,6 +604,7 @@ void FancyLineEdit::validate() AsyncValidationFuture future = validationFunction(text()); d->m_validatorWatcher->setFuture(future); + Utils::futureSynchronizer()->addFuture(future); return; }