fix(general): added check if role passed to ModelUtils.get exists

This commit is contained in:
Michał Cieślak 2023-07-20 12:23:02 +02:00 committed by Michał
parent 453d75b304
commit 6d7a018aaf
1 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <QAbstractItemModel>
#include <QDebug>
ModelUtilsInternal::ModelUtilsInternal(QObject* parent)
: QObject(parent)
{
@ -45,7 +46,10 @@ QVariantMap ModelUtilsInternal::get(QAbstractItemModel *model, int row) const
QVariant ModelUtilsInternal::get(QAbstractItemModel *model,
int row, const QString &roleName) const
{
return model->data(model->index(row, 0), roleByName(model, roleName));
if (auto role = roleByName(model, roleName); role != -1)
return model->data(model->index(row, 0), roleByName(model, roleName));
return {};
}
bool ModelUtilsInternal::contains(QAbstractItemModel* model,