Hi,

I've started a custom model for a treeview, the code for the model is as follows:

Qt Code:
  1. #include "dacantreemodel.h"
  2.  
  3. DACanTreeModel::DACanTreeModel(QObject *parent)
  4. {
  5. }
  6.  
  7. DACanTreeModel::~DACanTreeModel()
  8. {
  9. }
  10.  
  11. QModelIndex DACanTreeModel::index( int row, int column, const QModelIndex& parent) const
  12. {
  13. return QModelIndex();
  14. }
  15.  
  16.  
  17. int DACanTreeModel::rowCount(const QModelIndex &parent) const
  18. {
  19. return m_oTreeItems.count();
  20. }
  21.  
  22. int DACanTreeModel::columnCount(const QModelIndex &parent) const
  23. {
  24. return 4;
  25. }
  26.  
  27. QVariant DACanTreeModel::data(const QModelIndex &index, int role) const
  28. {
  29. QVariant data;
  30.  
  31. if (!index.isValid())
  32. return QVariant();
  33. if( role != Qt::DisplayRole )
  34. return QVariant();
  35. if(index.column() > 4 )
  36. {
  37. return QVariant();
  38. }
  39. if( role == Qt::DisplayRole )
  40. data = "Test";
  41.  
  42. return data;
  43. }
  44.  
  45. QVariant DACanTreeModel::headerData(int section, Qt::Orientation orientation,
  46. int role) const
  47. {
  48. if (role != Qt::DisplayRole)
  49. return QVariant();
  50.  
  51. if (orientation == Qt::Horizontal)
  52. return m_Headers[section];
  53. else
  54. return QVariant();
  55. }
  56.  
  57.  
  58. QModelIndex DACanTreeModel::parent(const QModelIndex &index) const
  59. {
  60. return QModelIndex();
  61. }
  62.  
  63. void DACanTreeModel::setHeaders( QStringList& headers )
  64. {
  65. m_Headers = headers;
  66. }
  67.  
  68. void DACanTreeModel::addData( QString strId )
  69. {
  70. CMessage* pMess = new CMessage();
  71. m_oTreeItems.insert( strId, (QObject*)pMess );
  72. }
To copy to clipboard, switch view to plain text mode 

I have a QTreeView which sets the model to the above. When I call addData I want an item to be added to the tree but nothing is happening, I guess I'm missing something here?
In the data function I'm just setting it to 'Test' just to see if this would appear. I have not implemented the index() or the parent() method yet. How do I get something to be put into the tree?

Regards,
Steve