fix(StatusQ): check if role exists in ModelUtils::contains

Without the check, asking for not existing role led to segfault.
This commit is contained in:
Michał Cieślak 2023-11-22 10:37:13 +01:00 committed by Michał
parent 24f2540ffa
commit a915f48fd9
1 changed files with 7 additions and 1 deletions

View File

@ -95,7 +95,13 @@ bool ModelUtilsInternal::contains(QAbstractItemModel* model,
Qt::MatchFlags flags = Qt::MatchFixedString; // Qt::CaseInsensitive by default
if(mode == Qt::CaseSensitive) flags |= Qt::MatchCaseSensitive;
const auto indexes = model->match(model->index(0, 0), roleByName(model, roleName), value, 1, flags);
auto role = roleByName(model, roleName);
if (role == -1)
return false;
const auto indexes = model->match(model->index(0, 0), role, value, 1, flags);
return !indexes.isEmpty();
}