GenericProjectManager: Do not crash on removing all files

When removing all files from a generic project QC crashed on
trying to access the first item of the empty file list.

Change-Id: I85045bf126f4e12575305466f0f4a6c4191176d3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Christian Stenger
2019-07-18 09:28:34 +02:00
parent 7b4cde9d65
commit 4c6c3de53b
2 changed files with 9 additions and 6 deletions

View File

@@ -382,10 +382,13 @@ void GenericProject::parseProject(RefreshOptions options)
}
}
QString GenericProject::findCommonSourceRoot(const QStringList &list)
FilePath GenericProject::findCommonSourceRoot()
{
QString root = list.front();
for (const QString &item : list) {
if (m_files.isEmpty())
return FilePath::fromFileInfo(QFileInfo(m_filesFileName).absolutePath());
QString root = m_files.front();
for (const QString &item : m_files) {
if (root.length() > item.length())
root.truncate(item.length());
@@ -396,7 +399,7 @@ QString GenericProject::findCommonSourceRoot(const QStringList &list)
}
}
}
return QFileInfo(root).absolutePath();
return FilePath::fromString(QFileInfo(root).absolutePath());
}
void GenericProject::refresh(RefreshOptions options)
@@ -408,7 +411,7 @@ void GenericProject::refresh(RefreshOptions options)
auto newRoot = std::make_unique<GenericProjectNode>(this);
// find the common base directory of all source files
Utils::FilePath baseDir = FilePath::fromFileInfo(QFileInfo(findCommonSourceRoot(m_files)));
Utils::FilePath baseDir = findCommonSourceRoot();
for (const QString &f : m_files) {
FileType fileType = FileType::Source; // ### FIXME

View File

@@ -66,7 +66,7 @@ private:
QStringList processEntries(const QStringList &paths,
QHash<QString, QString> *map = nullptr) const;
static QString findCommonSourceRoot(const QStringList &list);
Utils::FilePath findCommonSourceRoot();
void refreshCppCodeModel();
void updateDeploymentData();
void activeTargetWasChanged();