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 <jaroslaw.kobus@qt.io>
This commit is contained in:
Eike Ziller
2024-05-16 09:36:41 +02:00
parent 982ad24243
commit f7120daa2e

View File

@@ -5,6 +5,7 @@
#include "camelcasecursor.h" #include "camelcasecursor.h"
#include "execmenu.h" #include "execmenu.h"
#include "futuresynchronizer.h"
#include "historycompleter.h" #include "historycompleter.h"
#include "hostosinfo.h" #include "hostosinfo.h"
#include "icon.h" #include "icon.h"
@@ -98,6 +99,7 @@ class FancyLineEditPrivate : public QObject
{ {
public: public:
explicit FancyLineEditPrivate(FancyLineEdit *parent); explicit FancyLineEditPrivate(FancyLineEdit *parent);
~FancyLineEditPrivate();
bool eventFilter(QObject *obj, QEvent *event) override; 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) bool FancyLineEditPrivate::eventFilter(QObject *obj, QEvent *event)
{ {
int buttonIndex = -1; 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) void FancyLineEdit::setValidationFunction(const FancyLineEdit::ValidationFunction &fn)
{ {
d->m_validationFunction = fn; d->m_validationFunction = fn;
validate(); validate();
} }
/*!
Returns the default validation function, which synchonously executes the line edit's
validator.
\sa setValidationFunction()
*/
FancyLineEdit::ValidationFunction FancyLineEdit::defaultValidationFunction() FancyLineEdit::ValidationFunction FancyLineEdit::defaultValidationFunction()
{ {
return &FancyLineEdit::validateWithValidator; return &FancyLineEdit::validateWithValidator;
@@ -581,6 +604,7 @@ void FancyLineEdit::validate()
AsyncValidationFuture future = validationFunction(text()); AsyncValidationFuture future = validationFunction(text());
d->m_validatorWatcher->setFuture(future); d->m_validatorWatcher->setFuture(future);
Utils::futureSynchronizer()->addFuture(future);
return; return;
} }