aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2021-08-24 13:17:07 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2021-08-24 13:53:48 +0000
commitc7de2a224f096af73373464554761e31b4cf3d07 (patch)
treebf61170f25578348d77d799e7908d2118452874a
parentc129ecfc3c5de6fb384ac7acf078c5ee47264be2 (diff)
QmlDesigner: Fix crash
There may exist components that do not belong to any project. Task-number: QTCREATORBUG-26166 Change-Id: I77f5ec9c5d718300a38db203f9b5d1b1a4e96d1f Reviewed-by: Tapani Mattila <tapani.mattila@qt.io> Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--src/plugins/qmldesigner/components/navigator/navigatorview.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
index ada432401e..2606ea83a4 100644
--- a/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
+++ b/src/plugins/qmldesigner/components/navigator/navigatorview.cpp
@@ -184,7 +184,8 @@ void NavigatorView::clearExplorerWarnings()
for (ModelNode node : allNodes) {
if (node.metaInfo().isFileComponent()) {
const ProjectExplorer::FileNode *fnode = fileNodeForModelNode(node);
- fnode->setHasError(false);
+ if (fnode)
+ fnode->setHasError(false);
}
}
}
@@ -406,7 +407,18 @@ const ProjectExplorer::FileNode *NavigatorView::fileNodeForModelNode(const Model
{
QString filename = node.metaInfo().componentFileName();
Utils::FilePath filePath = Utils::FilePath::fromString(filename);
- ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(filePath);
+ ProjectExplorer::Project *currentProject = ProjectExplorer::SessionManager::projectForFile(
+ filePath);
+
+ if (!currentProject) {
+ filePath = Utils::FilePath::fromString(node.model()->fileUrl().toLocalFile());
+
+ /* If the component does not belong to the project then we can fallback to the current file */
+ currentProject = ProjectExplorer::SessionManager::projectForFile(filePath);
+ }
+ if (!currentProject)
+ return nullptr;
+
return currentProject->nodeForFilePath(filePath)->asFileNode();
}