Unable to assign [undefined] to QString
У меня есть следующий класс, описывающий модель
QHash<int, QByteArray> ContactsModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles[ContactRoles::NameRole] = "name";
roles[ContactRoles::SurnameRole] = "surname";
roles[ContactRoles::PhoneNumberRole] = "phoneNumber";
return roles;
}
QVariant ContactsModel::data(const QModelIndex &index, int role) const
{
if(!index.isValid() || index.row() > rowCount(index)){
return {};
}
const Contact& contact {m_contacts.at(index.row())};
switch (role){
case ContactRoles::NameRole: {
return QVariant::fromValue(contact.firstName());
} ; break;
case ContactRoles::SurnameRole: {
return QVariant::fromValue(contact.secondName());
} ; break;
case ContactRoles::PhoneNumberRole: {
return QVariant::fromValue(contact.phone());
} ; break;
default: {
return true;
} ; break;
}
}
в QMLописан делегат ListView
Column {
anchors.verticalCenter: root.verticalCenter
anchors.left: _contactBubble.right
anchors.leftMargin: Style.defaultOffset
Row {
spacing: Style.smallSpacing
BaseText {
text: name
}
BaseText {
text: surname
}
}
BaseText {
text: "+"+phoneNumber
color: Style.primaryColor
}
}
При запуске программы выдается ошибка в QML Unable to assign [undefined] to QString для name и surname
Как исправить эту ошибку?
Заранее спасибо