Skip to content

Commit af59b81

Browse files
Khushboo-dev-cppmicieslak
authored andcommitted
fix: This fixes the crash in ObjectProxy Model when the QML Context
becomes invalid
1 parent 8a6632b commit af59b81

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

toolkit/src/objectproxymodel.cpp

Lines changed: 9 additions & 2 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,9 +254,15 @@ 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();
261+
if (creationContext != nullptr && !creationContext->isValid())
262+
return nullptr;
263+
257264
auto parentContext = creationContext
258-
? creationContext : m_delegate->engine()->rootContext();
265+
? creationContext : m_delegate->engine()->rootContext();
259266

260267
auto context = new QQmlContext(parentContext);
261268
auto rowData = new QQmlPropertyMap(context);

0 commit comments

Comments
 (0)