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>
This commit is contained in:
Dirk Hohndel 2015-01-06 19:53:49 -08:00
parent 9511ee0294
commit 5a4d85bf7c

View file

@ -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