From d24fab71eb328a888849835b9252487fd5546043 Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Mon, 9 Feb 2015 14:44:43 +0100 Subject: [PATCH] Utils: Avoid accessing null pointer... ...and make sure model is propagated when using copy constructor. Change-Id: I95b95ebb7f6058adc73bc6e73b4f23a87012a2b2 Reviewed-by: hjk --- src/libs/utils/treemodel.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/treemodel.cpp b/src/libs/utils/treemodel.cpp index 784c8632a66..2ad8be41026 100644 --- a/src/libs/utils/treemodel.cpp +++ b/src/libs/utils/treemodel.cpp @@ -851,7 +851,7 @@ TreeModel::TreeModel(TreeItem *root, QObject *parent) m_root(root) { m_columnCount = 1; - m_root->m_model = this; + m_root->propagateModel(this); } TreeModel::~TreeModel() @@ -866,6 +866,7 @@ QModelIndex TreeModel::parent(const QModelIndex &idx) const return QModelIndex(); const TreeItem *item = itemFromIndex(idx); + QTC_ASSERT(item, return QModelIndex()); const TreeItem *parent = item->parent(); if (!parent || parent == m_root) return QModelIndex(); @@ -888,7 +889,9 @@ int TreeModel::rowCount(const QModelIndex &idx) const return m_root->rowCount(); if (idx.column() > 0) return 0; - return itemFromIndex(idx)->rowCount(); + const TreeItem *item = itemFromIndex(idx); + QTC_ASSERT(item, return 0); + return item->rowCount(); } int TreeModel::columnCount(const QModelIndex &idx) const