QmlDesigner: Fix crash when accessing optional

Change-Id: Ic80ea2558f6b41da127000441a75773d382f5a05
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Thomas Hartmann
2023-03-14 17:32:59 +01:00
parent 68bceb92cf
commit 925b08d6e6

View File

@@ -368,8 +368,11 @@ void ToolBarBackend::updateDocumentModel()
int ToolBarBackend::documentIndex() const
{
if (Core::EditorManager::currentDocument())
return Core::DocumentModel::indexOfDocument(Core::EditorManager::currentDocument()).value();
if (Core::EditorManager::currentDocument()) {
std::optional index = Core::DocumentModel::indexOfDocument(
Core::EditorManager::currentDocument());
return index.value_or(-1);
}
return -1;
}