From f9acfbc22439b6aa3a594713aeb4baf16819a074 Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Wed, 3 Apr 2024 21:15:45 +0200 Subject: [PATCH] SimpleTreeModel: Handle null root --- src/core/simpletreemodel.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/simpletreemodel.h b/src/core/simpletreemodel.h index 773962b6..8e1b4161 100644 --- a/src/core/simpletreemodel.h +++ b/src/core/simpletreemodel.h @@ -99,12 +99,14 @@ QModelIndex SimpleTreeModel::parent(const QModelIndex &idx) const { template int SimpleTreeModel::rowCount(const QModelIndex &parent) const { T *item = IndexToItem(parent); + if (!item) return 0; return item->children.count(); } template bool SimpleTreeModel::hasChildren(const QModelIndex &parent) const { T *item = IndexToItem(parent); + if (!item) return false; if (item->lazy_loaded) return !item->children.isEmpty(); else @@ -114,13 +116,13 @@ bool SimpleTreeModel::hasChildren(const QModelIndex &parent) const { template bool SimpleTreeModel::canFetchMore(const QModelIndex &parent) const { T *item = IndexToItem(parent); - return !item->lazy_loaded; + return item && !item->lazy_loaded; } template void SimpleTreeModel::fetchMore(const QModelIndex &parent) { T *item = IndexToItem(parent); - if (!item->lazy_loaded) { + if (item && !item->lazy_loaded) { LazyPopulate(item); } }