diff options
author | Caroline Chao <caroline.chao@digia.com> | 2014-10-09 12:26:28 +0200 |
---|---|---|
committer | Caroline Chao <caroline.chao@digia.com> | 2014-10-09 16:00:07 +0200 |
commit | eba86be60e546e766790ba0a6649665c8f275d5e (patch) | |
tree | 3d1dd49455fdc1a7ecada9b4c6930c4504d6070c | |
parent | 6a9d28886a02075e0a38309a7444122cdf9adb9c (diff) |
Check index validity before querrying data from model
Change-Id: Ifa48f526e9da38116ecfe5572cfad5cbb48208b8
Reviewed-by: Niels Weber <niels.weber@digia.com>
-rw-r--r-- | src/model.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/model.cpp b/src/model.cpp index 9baad5a..b2b9fe0 100644 --- a/src/model.cpp +++ b/src/model.cpp @@ -65,7 +65,7 @@ int Model::rowCount(const QModelIndex &parent) const QVariant Model::data(const QModelIndex &index, int role) const { QVariant variant; - if (m_data.count() > 0) { + if (m_data.count() > 0 && index.row() > -1) { variant = m_data.at(index.row()).value(m_roleNames.value(role)); // Hack to make it possible to filter by reference if (variant.type() == QVariant::Map && m_roleNames.value(role) == "day") { @@ -164,7 +164,11 @@ void Model::setFileNameTag(const QString &newTag) QVariant Model::data(int index, const QString &role) const { - return data(this->index(index, 0), m_roleNames.key(role.toLatin1())); + if (index > -1) + return data(this->index(index, 0), m_roleNames.key(role.toLatin1())); + else + return QVariant(); + } void Model::onFinished(EnginioReply *reply) |