I'm using QTableView with QAbstractTableModel and I'm adding rows on a signal. When I get a new signal, I delete the exiting rows and add the rows obtained newly.
The problem I'm facing is, the data to the new row is getting added properly, but every time, some blank rows are getting added, whose count is getting increased.
Qt Code:
  1. class CTableModel : public QAbstractTableModel
  2. {
  3. private:
  4. QList<CTableData *> m_data;
  5. QFileIconProvider iconProvider;
  6. public:
  7. ...
  8. ...
  9.  
  10. int rowCount(const QModelIndex &) const
  11. {
  12. qDebug() << "Row Count - " << m_data.count();
  13. return m_data.count();
  14. }
  15. int columnCount(const QModelIndex &) const
  16. {
  17. return 3;
  18. }
  19. // So before new signal, I call this function to delete all the rows data.
  20. void clearData(void)
  21. {
  22. qDeleteAll(m_data);
  23. m_data.clear();
  24. }
  25. };
To copy to clipboard, switch view to plain text mode 

And my data class goes like this
Qt Code:
  1. class CTableData
  2. {
  3. public:
  4. enum Type { File, Folder };
  5. CTableData()
  6. {
  7. ;
  8. }
  9. CTableData(Type & type, QString & path, QString size)
  10. {
  11. m_type = type;
  12. m_path = path;
  13. m_size = size;
  14. }
  15. ~CTableData() { }
  16.  
  17. void addData(Type & type, QString & path, QString size)
  18. {
  19. m_type = type;
  20. m_path = path;
  21. m_size = size;
  22. }
  23.  
  24. Type type(void) const
  25. {
  26. return m_type;
  27. }
  28.  
  29. QString path(void) const
  30. {
  31. return m_path;
  32. }
  33. QString size(void) const
  34. {
  35. return m_size;
  36. }
  37. private:
  38. Type m_type;
  39. QString m_path;
  40. QString m_size;
  41. };
To copy to clipboard, switch view to plain text mode 

And this is how I'm adding rows
Qt Code:
  1. // This slot gets called on an update signal.
  2. void MainWidget::selectedItemsChanged()
  3. {
  4. QModelIndexList selectedFiles;
  5. QModelIndexList selectedDirectories;
  6. QModelIndexList unselectedFiles;
  7. QModelIndexList unselectedDirectories;
  8.  
  9. m_checkProxy->checkedState()
  10. .checkedLeafSourceModelIndexes(selectedFiles)
  11. .checkedBranchSourceModelIndexes(selectedDirectories)
  12. .uncheckedLeafSourceModelIndexes(unselectedFiles)
  13. .uncheckedBranchSourceModelIndexes(unselectedDirectories);
  14.  
  15. QStringList listOfSelectedItems;
  16. QString list = QString("Selected files: %1").arg(selectedFiles.count());
  17.  
  18. model->clearData();
  19. CTableData::Type type;
  20.  
  21. foreach (const QModelIndex index, selectedFiles)
  22. {
  23. list = index.data(QFileSystemModel::FilePathRole).toString();
  24. QModelIndex sizeIndex = index.model()->index(index.row(), 1, index.parent());
  25. type = CTableData::File;
  26. model->append(new CTableData(type, list, sizeIndex.data().toString()));
  27. }
  28.  
  29. foreach (const QModelIndex index, selectedDirectories)
  30. {
  31. list = index.data(QFileSystemModel::FilePathRole).toString();
  32. type = CTableData::Folder;
  33. model->append(new CTableData(type, list, QString()));
  34. }
  35. }
To copy to clipboard, switch view to plain text mode 

Please help me delete extra blank rows that I get on call of this void MainWidget::selectedItemsChanged() slot.
Thank you.