PDA

View Full Version : invalid QModelIndex



Talei
18th January 2010, 18:06
Hello.
I try to write QAbstractTableModel but i have problem with index.
My test class:

class cmodel : public QAbstractTableModel
{
Q_OBJECT

public:
cmodel( QObject *parent = 0);
~cmodel();

QVariant data(const QModelIndex &index, int role) const;
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole);
int rowCount(const QModelIndex &parent) const;
int columnCount(const QModelIndex &parent) const;
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
Qt::ItemFlags flags(const QModelIndex &index) const;

private:
QStringList listaStr, listaUrl;
};
and function

void MainWindow::on_pushButton_clicked()
{
QStringList str;
str << "1" << "2" << "3";
cmodel *m = new cmodel( this );
QModelIndex index = m->index( 0, 0, QModelIndex() );
m->setData( index, str, Qt::DisplayRole );
ui->tableView->setModel( m );
}

but in setData my index is invalid ( index.isValid() is false ).
Why is that?

Thanks for any suggestion and sorry for my "enrgish"
best regards

Talei
18th January 2010, 20:21
My fault,
I forget to "add" insertRows. Right now everything works as expected.

Best regards