QmlDesigner: Fix potential crash

The new selected ModelNode (m_selectedNode) was set to early, since
we defer the creation of the QML frontend.

We have to set m_selectedNode when the QML frontend is actually created.
Otherwise, we might access an uninitialized QML frontend.

Change-Id: I630b103246c414c737c977e233180723df0c3160
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2019-08-28 12:03:12 +02:00
parent 217f0c0305
commit c61702fca4
2 changed files with 24 additions and 16 deletions

View File

@@ -389,6 +389,8 @@ void PropertyEditorView::resetView()
if (model() == nullptr)
return;
setSelelectedModelNode();
m_locked = true;
if (debug)
@@ -526,21 +528,16 @@ void PropertyEditorView::removePropertyFromModel(const PropertyName &propertyNam
m_locked = false;
}
void PropertyEditorView::selectedNodesChanged(const QList<ModelNode> &selectedNodeList,
const QList<ModelNode> &lastSelectedNodeList)
void PropertyEditorView::selectedNodesChanged(const QList<ModelNode> &,
const QList<ModelNode> &)
{
Q_UNUSED(lastSelectedNodeList);
if (selectedNodeList.isEmpty())
select(ModelNode());
else
select(selectedNodeList.constFirst());
select();
}
void PropertyEditorView::nodeAboutToBeRemoved(const ModelNode &removedNode)
{
if (m_selectedNode.isValid() && removedNode.isValid() && m_selectedNode == removedNode)
select(m_selectedNode.parentProperty().parentModelNode());
select();
}
void PropertyEditorView::modelAttached(Model *model)
@@ -686,19 +683,29 @@ void PropertyEditorView::nodeIdChanged(const ModelNode& node, const QString& new
}
}
void PropertyEditorView::select(const ModelNode &node)
void PropertyEditorView::select()
{
if (m_qmlBackEndForCurrentType)
m_qmlBackEndForCurrentType->emitSelectionToBeChanged();
if (QmlObjectNode(node).isValid())
m_selectedNode = node;
else
m_selectedNode = ModelNode();
delayedResetView();
}
void PropertyEditorView::setSelelectedModelNode()
{
const auto selectedNodeList = selectedModelNodes();
m_selectedNode = ModelNode();
if (selectedNodeList.isEmpty())
return;
const ModelNode node = selectedNodeList.constFirst();
if (QmlObjectNode(node).isValid())
m_selectedNode = node;
}
bool PropertyEditorView::hasWidget() const
{
return true;

View File

@@ -105,7 +105,8 @@ private: //functions
void updateSize();
void setupPanes();
void select(const ModelNode& node);
void select();
void setSelelectedModelNode();
void delayedResetView();
void setupQmlBackend();