tntcoda
22nd June 2008, 15:14
Hi,
I'm having some problems working out how to implement the data() function from QAbstractTableModel for use in a QTableView model.
My data is stored in a large vector, that the model (which is read only) has a pointer to, I set up the headerData() function, so all the column names are correct and that works fine. rowCount and ColumnCount are also in my class, correct i think.
I have 4 columns, and x number or rows, so i just need some help with returning the correct data from the data() function.
Here is my code, im basically not sure how i use the index and role values in order to know a) which column the data is from, and b) the row number. I need these 2 values in order to know which data to get from the data vector. For example if its from column 2 and row 5, i know i need to return the subject from element 5 in the vector. Is it as simple as role is the column and index is the row? :confused:
QVariant QueueModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole)
return QVariant();
//return ....
}
Also, do i have to do anything special to keep the view updating? i.e if i change a value in the data vector and another point in my program (outside of the model), will the view just update automatically?
Thanks alot for any tips,
Jack
I'm having some problems working out how to implement the data() function from QAbstractTableModel for use in a QTableView model.
My data is stored in a large vector, that the model (which is read only) has a pointer to, I set up the headerData() function, so all the column names are correct and that works fine. rowCount and ColumnCount are also in my class, correct i think.
I have 4 columns, and x number or rows, so i just need some help with returning the correct data from the data() function.
Here is my code, im basically not sure how i use the index and role values in order to know a) which column the data is from, and b) the row number. I need these 2 values in order to know which data to get from the data vector. For example if its from column 2 and row 5, i know i need to return the subject from element 5 in the vector. Is it as simple as role is the column and index is the row? :confused:
QVariant QueueModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole)
return QVariant();
//return ....
}
Also, do i have to do anything special to keep the view updating? i.e if i change a value in the data vector and another point in my program (outside of the model), will the view just update automatically?
Thanks alot for any tips,
Jack