summaryrefslogtreecommitdiff
path: root/ui/qt/uat_model.cpp
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2016-10-21 13:59:11 +0200
committerPeter Wu <peter@lekensteyn.nl>2016-10-21 14:13:43 +0000
commit991e0747a3b0bbeddb27dc29e53fa6dbb5c68e4b (patch)
tree2c3555e6dd9a1fdbde87df119616addd91539812 /ui/qt/uat_model.cpp
parent67bfdf28714a5945a78aef9d745d88fd69972578 (diff)
downloadwireshark-991e0747a3b0bbeddb27dc29e53fa6dbb5c68e4b.tar.gz
Qt: fix weird tree expander that results in a crash
According to the Qt documentation, rowCount and columnCount must return 0 when a valid parent index is passed to a table model. Otherwise deep recursion would occur resulting in a stack overflow in Qt4. Change-Id: I60bb15384470861013591e149c0f285ea1bdf9a7 Fixes: v2.3.0rc0-1002-g1cd2255 ("Qt: convert UatDialog to model/view pattern, improve UX") Reviewed-on: https://code.wireshark.org/review/18354 Reviewed-by: Michal Labedzki <michal.labedzki@tieto.com> Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com> Tested-by: Michal Labedzki <michal.labedzki@tieto.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Diffstat (limited to 'ui/qt/uat_model.cpp')
-rw-r--r--ui/qt/uat_model.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/ui/qt/uat_model.cpp b/ui/qt/uat_model.cpp
index e8c6ec1dcb..6927674190 100644
--- a/ui/qt/uat_model.cpp
+++ b/ui/qt/uat_model.cpp
@@ -47,7 +47,6 @@ Qt::ItemFlags UatModel::flags(const QModelIndex &index) const
if (!index.isValid())
return 0;
- // Note: Qt::ItemNeverHasChildren is not just for optimization, it avoids crashes too with QTreeView...
Qt::ItemFlags flags = QAbstractTableModel::flags(index);
flags |= Qt::ItemIsEditable;
return flags;
@@ -109,13 +108,23 @@ QVariant UatModel::headerData(int section, Qt::Orientation orientation, int role
return uat_->fields[section].title;
}
-int UatModel::rowCount(const QModelIndex &/*parent*/) const
+int UatModel::rowCount(const QModelIndex &parent) const
{
+ // there are no children
+ if (parent.isValid()) {
+ return 0;
+ }
+
return uat_->raw_data->len;
}
-int UatModel::columnCount(const QModelIndex &/*parent*/) const
+int UatModel::columnCount(const QModelIndex &parent) const
{
+ // there are no children
+ if (parent.isValid()) {
+ return 0;
+ }
+
return uat_->ncols;
}