On button click i am calling updateEntries() function which I am expecting it should add rows into the model and show the tableview on the screen.But i am not seeing any table with data.
Also i have one observation if i give hardcoded values m_list.size() > 0 ie. 1 or greater than 0 in XYZ::rowCount() function then on button click i am seeing table with data. why this happening could anyone explain me? I am using Tableview in .qml file.
Also my qml part is working fine.I also tested using Listmodel in qml.so it is showing table data.
so i hoping my qml code is working fine but having issue in model class.
int XYZ::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return m_list.size();
}
int XYZ::columnCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
return 1;
}
void XYZ::updateEntries() {
QList<MyStruct> hardcodedEntries = {
{ "1", "2", "3", "4", "5", "6", "7", "8" },
{ "10", "20", "30", "40", "50", "60", "70", "80" }
};
// Clear existing data
beginResetModel();
m_list.clear();
endResetModel();
// Insert new rows
beginInsertRows(QModelIndex(), 0, hardcodedEntries.size() - 1);
for (const MyStruct &entry : hardcodedEntries) {
m_list.append(entry);
}
endInsertRows();
emit dataChanged(index(0, 0), index(m_logEntries.size() - 1, columnCount() - 1));
}
QVariant XYZ::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || index.row() >= m_logEntries.size() || index.column() >= columnCount()) {
return QVariant();
}
const MyStruct &entry = m_list.at(index.row());
switch (role) {
case Role1:
return entry.parameter1;
case Role2:
return entry.parameter2;
case Role3:
return entry.parameter3;
case Role4:
return entry.parameter4;
case Role5:
return entry.parameter5;
case Role6:
return entry.parameter6;
case Role7:
return entry.parameter7;
default:
return QVariant();
}
}
I am expecting that after clicking on ‘ShowTable’ button i should see table
because i am calling updateEntries() from .qml file.
Also i verified that rowCount() is increasing after adding rows but not seeing in table anything.