I am lazy, because it cost 10 ms for 100 rows to delete and insert. I found the answer in a brainstorming session last night.

My mistake was simple. I have not cleaned the data before I save new.

This is my code for others:

Qt Code:
  1. void TxTableModel::parseXml(const QByteArray &xml)
  2. {
  3. QXmlInputSource inputSource;
  4. TxSaxTableHandler handler(&m_Data, false);
  5.  
  6. inputSource.setData(xml);
  7. reader.setContentHandler(&handler);
  8. reader.setErrorHandler(&handler);
  9.  
  10. QModelIndexList selectedList = parent->selectionModel()->selectedRows();
  11.  
  12. beginResetModel();
  13. m_Data.clearData();
  14. reader.parse(inputSource);
  15. endResetModel();
  16.  
  17. for( int i=0; i<selectedList.count(); i++) {
  18. parent->selectRow(selectedList.at(i).row());
  19. }
  20. }
To copy to clipboard, switch view to plain text mode