Thanks for the replies, cause I've really been struggling with this. I think I have reimplemented all needed functions. Here's whats in my header file so far and that I have defined in my source file.
ConnectionListModel
(QObject *parent
= 0);
~ConnectionListModel();
//Required items to make this model work
//required items to be able to edit items
//Required to be able to resize the model (add & remove shit)
private:
QList<connectionData> connectionList;
ConnectionListModel(QObject *parent = 0);
~ConnectionListModel();
//Required items to make this model work
int rowCount(const QModelIndex &index = QModelIndex()) const;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
//required items to be able to edit items
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
Qt::ItemFlags flags(const QModelIndex &index) const;
//Required to be able to resize the model (add & remove shit)
bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
private:
QList<connectionData> connectionList;
To copy to clipboard, switch view to plain text mode
One thing that I noticed when stepping through my code while trying to add an item was that I'm never calling my setData funciton with a valid index, so it always skips over the code and never emits the signal that the data changed.
So now my question is how do I get a valid index? I thought that calling index(0) would give me the index for the item that I just inserted at the front of the list, but that isn't the case.
Here's the calling code
//where m_pSessoinModel is a connectionlistmodel
ConnectionListModel::connectionData addMe;
m_pSessionModel->insertRows(0, 1); //inserting 1 row before row #0
m_pSessionModel->setData( m_pSessionModel->index(0), &addMe);
//where m_pSessoinModel is a connectionlistmodel
ConnectionListModel::connectionData addMe;
m_pSessionModel->insertRows(0, 1); //inserting 1 row before row #0
m_pSessionModel->setData( m_pSessionModel->index(0), &addMe);
To copy to clipboard, switch view to plain text mode
Any ideas? The examples online are not very helpful here.
Paul
Bookmarks