Wizards: Fix crash

... if the project has no classes.
Apparently, one must not call QFutureInterface::reportsResults() with an
empty list, so prevent that.
Also, for simplicity, make sure we have only one possible point of
deletion for the watcher.

Change-Id: I68c3813459533ced86610e88bea81b6a9d170ca5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
Christian Kandeler
2020-08-05 16:33:12 +02:00
parent 6c4c7ec751
commit 1f72edcda9

View File

@@ -632,7 +632,7 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
if (!classesFilter) if (!classesFilter)
return; return;
classesFilter->prepareSearch({}); classesFilter->prepareSearch({});
const auto watcher = new QFutureWatcher<LocatorFilterEntry>(lineEdit); const auto watcher = new QFutureWatcher<LocatorFilterEntry>;
const auto handleResults = [this, lineEdit, watcher](int firstIndex, int endIndex) { const auto handleResults = [this, lineEdit, watcher](int firstIndex, int endIndex) {
QSet<QString> namespaces; QSet<QString> namespaces;
QStringList classes; QStringList classes;
@@ -681,12 +681,14 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit)
} }
completionList.sort(); completionList.sort();
lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit)); lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit));
watcher->deleteLater();
}; };
QObject::connect(watcher, &QFutureWatcher<LocatorFilterEntry>::resultsReadyAt, lineEdit, QObject::connect(watcher, &QFutureWatcher<LocatorFilterEntry>::resultsReadyAt, lineEdit,
handleResults); handleResults);
QObject::connect(watcher, &QFutureWatcher<LocatorFilterEntry>::finished,
watcher, &QFutureWatcher<LocatorFilterEntry>::deleteLater);
watcher->setFuture(runAsync([classesFilter](QFutureInterface<LocatorFilterEntry> &f) { watcher->setFuture(runAsync([classesFilter](QFutureInterface<LocatorFilterEntry> &f) {
const QList<LocatorFilterEntry> matches = classesFilter->matchesFor(f, {}); const QList<LocatorFilterEntry> matches = classesFilter->matchesFor(f, {});
if (!matches.isEmpty())
f.reportResults(QVector<LocatorFilterEntry>(matches.cbegin(), matches.cend())); f.reportResults(QVector<LocatorFilterEntry>(matches.cbegin(), matches.cend()));
f.reportFinished(); f.reportFinished();
})); }));