Browse Source

Don't crash on bad index

QGC4.4
Gus Grubba 6 years ago
parent
commit
88b201efec
  1. 8
      src/QmlControls/QmlObjectListModel.cc
  2. 2
      src/QmlControls/QmlObjectListModel.h

8
src/QmlControls/QmlObjectListModel.cc

@ -32,6 +32,14 @@ QmlObjectListModel::~QmlObjectListModel() @@ -32,6 +32,14 @@ QmlObjectListModel::~QmlObjectListModel()
}
QObject* QmlObjectListModel::get(int index)
{
if (index < 0 || index >= _objectList.count()) {
return nullptr;
}
return _objectList[index];
}
int QmlObjectListModel::rowCount(const QModelIndex& parent) const
{
Q_UNUSED(parent);

2
src/QmlControls/QmlObjectListModel.h

@ -27,7 +27,7 @@ public: @@ -27,7 +27,7 @@ public:
/// a dirty property and dirtyChanged signal.
Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
Q_INVOKABLE QObject* get(int index) { return _objectList[index]; }
Q_INVOKABLE QObject* get(int index);
// Property accessors

Loading…
Cancel
Save