I am developing an application that updates the data in QTableView with apache server once per second. The server renders the data as XML table. Number of columns is constant, but the number of rows changes each time. The data in the rows may also vary.

To convert the XML into the data, I created a class TxTableData, which is used in TxTableModel (child of QAbstractTableModel). Also TxTableModel uses QTimer to update data from the server.

The problem is that if the number of lines decreases - QTableview did not react to it. When the number of rows increases - it's all right.

Qt Code:
  1. void TxTableModel::refreshData()
  2. {
  3. TxRequest request;
  4. request.setObject("order");
  5. request.setMethod("getlist");
  6. request.addParam("begin_time", 60*60*4);
  7. request.addParam("end_time", 60*4);
  8.  
  9. http.queryAsync(request);
  10. }
  11.  
  12. void TxTableModel::parseXml(const QByteArray &xml)
  13. {
  14. QXmlInputSource inputSource;
  15. TxSaxTableHandler handler(&m_Data, false);
  16.  
  17. inputSource.setData(xml);
  18. reader.setContentHandler(&handler);
  19. reader.setErrorHandler(&handler);
  20.  
  21. beginResetModel();
  22. reader.parse(inputSource);
  23. endResetModel();
  24. }
  25.  
  26. void TxTableModel::httpDone(bool error)
  27. {
  28. if (error) {
  29. qDebug() << http.errorString();
  30. } else {
  31. parseXml(http.readAll());
  32. }
  33. }
  34.  
  35. void TxTableModel::timerDone()
  36. {
  37. refreshData();
  38. }
To copy to clipboard, switch view to plain text mode 

How to update the data in QTableview if the number of rows can change?