PDA

View Full Version : QSortFilterProxyModel - crash



steg90
4th June 2008, 11:20
Hi,

I don't mean this to be a double post, so please forgive me if I should have added this to my last thread.

I have a model derived from QAbstractTabelModel, this is used with a QTableView. To sort the data in the table, I used the following :



m_pModel = new DACanTreeModel();
m_proxyModel = new QSortFilterProxyModel(this);
m_proxyModel->setDynamicSortFilter(true);
m_proxyModel->setSourceModel(m_pModel);

QStringList list;
list << "ECU" << "Signal" << "Signal Data" << "Real value" << "Unit" << "Count";
m_pModel->setHeaders( list );

ui.canTreeView->setSortingEnabled( true );
ui.canTreeView->setModel( m_proxyModel);



For some reason, data is now not being shown in the table view unless I click on the column headers and when I do, a crash occurs, is the above code wrong? If I set the views model to m_pModel, the data appears, but I cannot sort it.

Thanks,
Steve

steg90
4th June 2008, 11:47
Ok, found exactly where the crash is occuring, and it is in my model :



int row = theApp->m_dcb[theApp->m_nCanSelected].GetSignalList()->count();
beginInsertRows(QModelIndex(), row, row );
endInsertRows();


This is only happening since I set my view to use the QSortFilterProxyModel. I guess it must be the QModelIndex() call?

Regards,
Steve

steg90
4th June 2008, 13:43
Hi,

Does anybody know how to get the QModelIndex for the proxy model?

Regards,
Steve

wysota
4th June 2008, 14:14
QAbstractItemModel::index(), QAbstractProxyModel::mapToSource(), QAbstractProxyModel::mapFromSource().