Table Model / View Problem -- Data Not Displaying
Hello everyone,
I'm having a difficult time getting a table set up. I subclassed QAbstractTableModel as such:
Code:
int FileModel
::rowCount(const QModelIndex &parent
) const {
return files.count();
}
int FileModel
::columnCount(const QModelIndex &parent
) const { return 4;
}
printf("row %d\n",(int)index.row());
if (!index.isValid())
if (index.row() >= files.size())
if (role == Qt::DisplayRole) {
printf("%s\n",files.value(file_list.at(index.row()))->m_path.c_str());
return QString(files.
value(file_list.
at(index.
row()))->m_path.
c_str());
} else {
}
}
I set the model in a view like this:
Code:
FileModel fmodel;
table->setModel(&fmodel);
table->setAlternatingRowColors(true);
table->show();
However, an empty table shows up with the correct number of rows and columns. I'm not sure why this is happening and I've tried just about everything I can think of.
Any ideas?
Thanks!
Re: Table Model / View Problem -- Data Not Displaying
The model gets automatically destroyed when going out of scope. Allocate it on the heap:
Code:
FileModel* fmodel = new FileModel(this);
table->setModel(fmodel);
PS. Have you noticed QDirModel? :)