ClangCodeModel: Fix crash on git diff/show

currentEditorChanged is emitted also for none TextEditors, so
check the qobject casted TextDocument before accessing it.

Change-Id: I57080221bec34b879f21e022029524818ea92569
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2018-03-01 12:33:48 +01:00
parent 35efebf6f8
commit 5e2ad9457f

View File

@@ -176,11 +176,12 @@ void ClangCurrentDocumentFilter::onCurrentEditorChanged(Core::IEditor *newCurren
m_currentEditor = newCurrent;
Core::IDocument *document = m_currentEditor->document();
QTC_ASSERT(document, return;);
auto *textDocument = qobject_cast<TextEditor::TextDocument *>(document);
m_currentPath = textDocument->filePath().toString();
} else {
reset();
if (auto *textDocument = qobject_cast<TextEditor::TextDocument *>(document)) {
m_currentPath = textDocument->filePath().toString();
return;
}
}
reset();
}
} // namespace ClangCodeModel