From 1f72edcda9f0173203344be53219b5ab2fefd116 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 5 Aug 2020 16:33:12 +0200 Subject: [PATCH] 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 --- src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp index 5c11d434006..9cfb13feac7 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonfieldpage.cpp @@ -632,7 +632,7 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit) if (!classesFilter) return; classesFilter->prepareSearch({}); - const auto watcher = new QFutureWatcher(lineEdit); + const auto watcher = new QFutureWatcher; const auto handleResults = [this, lineEdit, watcher](int firstIndex, int endIndex) { QSet namespaces; QStringList classes; @@ -681,13 +681,15 @@ void LineEditField::setupCompletion(FancyLineEdit *lineEdit) } completionList.sort(); lineEdit->setSpecialCompleter(new QCompleter(completionList, lineEdit)); - watcher->deleteLater(); }; QObject::connect(watcher, &QFutureWatcher::resultsReadyAt, lineEdit, handleResults); + QObject::connect(watcher, &QFutureWatcher::finished, + watcher, &QFutureWatcher::deleteLater); watcher->setFuture(runAsync([classesFilter](QFutureInterface &f) { const QList matches = classesFilter->matchesFor(f, {}); - f.reportResults(QVector(matches.cbegin(), matches.cend())); + if (!matches.isEmpty()) + f.reportResults(QVector(matches.cbegin(), matches.cend())); f.reportFinished(); })); }