summaryrefslogtreecommitdiffstats
path: root/qt-ui/divelogimportdialog.cpp
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-06 19:53:49 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2015-01-06 19:53:49 -0800
commit5a4d85bf7c011aeab2f61ce412fc4cb16980d62d (patch)
treee9945d44ca9551d749629778768196993e681fa1 /qt-ui/divelogimportdialog.cpp
parent9511ee029403c7e49989b49889d159f45d859770 (diff)
downloadsubsurface-5a4d85bf7c011aeab2f61ce412fc4cb16980d62d.tar.gz
Fix crash when importing CSV that requires change of separator
The dialog defaults to tab; if a file is indeed comma separated and one switches to that, data() could be called on a higher index before the model is re-populated. I'm a bit surprised why index.isValid() doesn't catch this, but the manual check appears to work. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/divelogimportdialog.cpp')
-rw-r--r--qt-ui/divelogimportdialog.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 4fb9b30d2..5ee964f72 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -217,7 +217,12 @@ QVariant ColumnNameResult::data(const QModelIndex &index, int role) const
if (index.row() == 0) {
return (columnNames[index.column()]);
}
- return QVariant(columnValues[index.row() -1][index.column()]);
+ // make sure the element exists before returning it - this might get called before the
+ // model is correctly set up again (e.g., when changing separators)
+ if (columnValues.count() > index.row() - 1 && columnValues[index.row() - 1].count() > index.column())
+ return QVariant(columnValues[index.row() - 1][index.column()]);
+ else
+ return QVariant();
}
int ColumnNameResult::rowCount(const QModelIndex &parent) const