Hi,

Can anybody please explain why the following keeps adding rows to my table view :

Qt Code:
  1. void DAStaticModel::setCanData( int nAmount )
  2. {
  3. if( nAmount <= 0 )
  4. return;
  5.  
  6. beginInsertRows(QModelIndex(), 0, 0 );
  7. endInsertRows();
  8.  
  9. }
  10.  
  11. QVariant DAStaticModel::data( const QModelIndex& index, int role) const
  12. {
  13. QVariant data;
  14.  
  15. if (!index.isValid())
  16. return QVariant();
  17.  
  18. if(index.column() > 3 )
  19. {
  20. return QVariant();
  21. }
  22.  
  23. if( role == Qt::DisplayRole )
  24. {
  25.  
  26. QString strId = "";
  27. static QMapIterator<QString, QObject*>i(*theApp->GetCanMap());
  28. static CanMessages* pMess = NULL;
  29. if( i.hasNext() && index.column() == 0 )
  30. {
  31. i.next();
  32. pMess = (CanMessages*)i.value();
  33. strId = i.key();
  34. }
  35. else
  36. if( !i.hasNext() ) // need to reset to begining of the list
  37. {
  38. i.toFront();
  39. }
  40.  
  41. switch( index.column() )
  42. {
  43. case 0:
  44. data = strId;
  45. break;
  46. case 2:
  47. {
  48. if( pMess )
  49. {
  50. data = pMess->m_strData;
  51. }
  52. }
  53. break;
  54. case 1:
  55. {
  56. if( pMess )
  57. {
  58. data = pMess->m_strTime;
  59. }
  60. }
  61. break;
  62. case 3:
  63. {
  64. if( pMess )
  65. {
  66. QString strCount;
  67. strCount.sprintf( "%d", pMess->m_nCount );
  68. data = strCount;
  69. }
  70. }
  71. break;
  72. }
  73. }
  74.  
  75. return data;
  76. }
  77.  
  78. int DAStaticModel::rowCount( const QModelIndex& parent ) const
  79. {
  80. return theApp->GetCanMap()->size();
  81. }
To copy to clipboard, switch view to plain text mode 

If I don't call the beginInsertRows / endInsertRows nothing is displayed in my table view.

Please note that the rowCount is always one...

Thanks,
Steve