Index: sources/model/MListModel.cpp =================================================================== diff -u -r8c7b9550b05f223be9d094e850e06f9ed80adb70 -r04922336fb5b75145d4b89343c77928da28f6ef6 --- sources/model/MListModel.cpp (.../MListModel.cpp) (revision 8c7b9550b05f223be9d094e850e06f9ed80adb70) +++ sources/model/MListModel.cpp (.../MListModel.cpp) (revision 04922336fb5b75145d4b89343c77928da28f6ef6) @@ -45,10 +45,18 @@ return QVariant(); } - // ensure the role is in the data and return it, otherwise return invalid - return (_data[vIndex.row()].find(vRole) != _data[vIndex.row()].end()) - ? _data[vIndex.row()][vRole] - : QVariant(); + // ensure the data is not empty + if ( _data.isEmpty() ) { return QVariant(); } + + // ensure the role is in the data + if ( _data[vIndex.row()].find(vRole) == _data[vIndex.row()].end()) { return QVariant(); } + + QVariant mData = _data[vIndex.row()][vRole]; + + // check if data is valid + if (! mData.isValid()) { return QVariant(); } + + return mData; } /*! @@ -57,15 +65,33 @@ */ QVariantMap View::MListModel::get(int vRow) const { - if (vRow < 0 || vRow >= rowCount()) { - return {}; - } + // Row bounds check + if (vRow < 0 || vRow >= rowCount()) { return {}; } QHash roles = roleNames(); + + // Check if roles are defined + if ( roles.isEmpty() ) { return {}; } + QVariantMap map; - for (auto it = roles.begin(); it != roles.end(); ++it) { - map[it.value()] = data(index(vRow, 0), it.key()); + for (auto it = roles.cbegin(); it != roles.cend(); ++it) { + const int role = it.key(); + const QByteArray roleName = it.value(); + + if ( roleName.isEmpty() ) { + qWarning() << "Empty role name for role id:" << role; + continue; + } + + QVariant value = data(index(vRow, 0), role); + if ( ! value.isValid() ) { + qWarning() << "Invalid value for role:" << roleName << "row:" << vRow; + continue; + } + + map.insert(QString::fromUtf8(roleName), value); } + return map; }