Skip to content

Commit b2b19d1

Browse files
fix: This fixes the crash in ObjectProxy Model when the QML Context
becomes invalid
1 parent 8a6632b commit b2b19d1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

toolkit/src/objectproxymodel.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ QVariant ObjectProxyModel::data(const QModelIndex& index, int role) const
7474

7575
if (m_delegate && m_exposedRolesSet.contains(role)) {
7676
const auto proxy = this->proxyObject(index.row());
77-
return proxy->property(m_roleNames[role]);
77+
if (proxy != nullptr)
78+
return proxy->property(m_roleNames[role]);
7879
}
7980

8081
return QIdentityProxyModel::data(index, role);
@@ -253,11 +254,14 @@ QObject* ObjectProxyModel::proxyObject(int index) const
253254
if (entry.proxy)
254255
return entry.proxy.get();
255256

257+
if (m_delegate == nullptr)
258+
return nullptr;
259+
256260
auto creationContext = m_delegate->creationContext();
257-
auto parentContext = creationContext
258-
? creationContext : m_delegate->engine()->rootContext();
261+
if (creationContext == nullptr || !creationContext->isValid())
262+
return nullptr;
259263

260-
auto context = new QQmlContext(parentContext);
264+
auto context = new QQmlContext(creationContext);
261265
auto rowData = new QQmlPropertyMap(context);
262266
auto model = sourceModel();
263267

0 commit comments

Comments
 (0)