Hi,

I'm using my own model derived from QAbstractTableModel. My class looks something like :

Qt Code:
  1. class DATreeModel : public QAbstractTableModel
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. DATreeModel(const QStringList &strings, QObject *parent = 0)
  7. : QAbstractTableModel(parent), stringList(strings) {}
  8.  
  9. DATreeModel(QObject *parent = 0);
  10. ~DATreeModel();
  11.  
  12. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  13. int columnCount(const QModelIndex &) const;
  14. QVariant data(const QModelIndex &index, int role) const;
  15. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  16. void setCanData( const QString& strData );
  17. void SetHeaders( QStringList& strHeaders );
  18.  
  19. private:
  20. QStringList stringList;
  21. QList<QString> m_Data;
  22. QStringList strHeaderList;
  23. };
To copy to clipboard, switch view to plain text mode 

This model is just read only so no need to override setData. Now the following snippet of code is used to set the data :

Qt Code:
  1. QVariant DATreeModel::data( const QModelIndex& index, int role) const
  2. {
  3. QVariant data;
  4.  
  5. if (!index.isValid())
  6. return QVariant();
  7.  
  8.  
  9. if (index.row() > (m_Data.size() / 4) )
  10. {
  11. return QVariant();
  12. }
  13.  
  14. if(index.column() > 3 )
  15. {
  16. return QVariant();
  17. }
  18.  
  19. if( role == Qt::DisplayRole )
  20. {
  21. // just return data at given column
  22. int nPos = index.column() + ( 4 * index.row() );
  23. if( nPos < m_Data.size() )
  24. data = m_Data.at( nPos );
  25.  
  26. }
  27.  
  28. return data;
  29. }
To copy to clipboard, switch view to plain text mode 

And the following is used to insert new data :
Qt Code:
  1. void DATreeModel::setCanData( const QString& strData )
  2. {
  3. m_Data.append(strData);
  4. QModelIndex nindex = index(m_Data.size(),0);;
  5. emit dataChanged(nindex, nindex );
  6. }
To copy to clipboard, switch view to plain text mode 

Alas, the table view is not 'refreshed' unless I click on the cells within it, I thought this would be automatic?

Any help would be much appreciated.

Steve