The use case is that i am populating the listView with the filtererd rows.
Here is the code.

Qt Code:
  1. class ModelFilterProxyModel : public QSortFilterProxyModel
  2. {
  3. Q_OBJECT
  4.  
  5. public:
  6. ModelFilterProxyModel(QObject *parent = 0);
  7. void SetSearchStr(QString str);
  8.  
  9. protected:
  10. virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
  11.  
  12. private:
  13. QString m_ManufSearchStr;
  14. };
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. bool ModelFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
  2. {
  3. bool status = false;
  4. bool found = false;
  5. QModelIndex indexMod = sourceModel()->index(sourceRow, DevicesModel::MODEL, sourceParent);
  6. QString modelStr = sourceModel()->data(indexMod).toString();
  7.  
  8. QModelIndex index = sourceModel()->index(sourceRow, DevicesModel::MANUFACTURER, sourceParent);
  9. QString manufacturetStr = sourceModel()->data(index).toString();
  10. bool found = false;
  11. // Checking for models by the specific manufacturer and eleminating duplicate models.
  12. for (int row = sourceRow; row >= 0 ; --row)
  13. {
  14. QModelIndex index1 = sourceModel()->index(row - 1, DevicesModel::MODEL, sourceParent);
  15. QModelIndex indexManf1 = sourceModel()->index(row - 1, DevicesModel::MANUFACTURER, sourceParent);
  16. QString modelStr1 = sourceModel()->data(index1).toString();
  17. QString manufacturetStr1 = sourceModel()->data(indexManf1).toString();
  18. if (modelStr == modelStr1 && manufacturetStr == manufacturetStr1)
  19. {
  20. found = true;
  21. // No need to search further - so break.
  22. break;
  23. }
  24. }
  25. if (!found && manufacturetStr == m_pPrivate->m_ManufSearchStr)
  26. {
  27. status = true;
  28. }
  29. return status;
  30. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. m_ModelProxyModel->setDynamicSortFilter(true);
  2. m_ModelProxyModel->setSourceModel(m_Model);
  3. m_ModelProxyModel->sort(DevicesModel::MODEL);
  4. m_Ui.modelListView->setModel(m_ModelProxyModel);
  5. m_Ui.modelListView->setModelColumn(DevicesModel::MODEL);
To copy to clipboard, switch view to plain text mode