PDA

View Full Version : selectedIems() not working with QSortFilterProxyModel



patcito
12th July 2006, 23:00
ok so when I select items in my tree and execute selectedItems() it just works as intended using this function:

void Getmyfiltr::on_pushButton_clicked(){

QList <QTreeWidgetItem *> selection;
selection << ui.treeWidget->selectedItems();

for(int i=0;i<selection.size();i++){
qDebug() << selection.at(i)->text(0);
}
qDebug() << selection.size();

}

but when I use my lineEdit to filter the content using that on_lineEdit_textChanged( const QString &) function and then hit the pushButton it just crashes the application with a segfault.

void Getmyfiltr::on_lineEdit_textChanged( const QString & filtr)
{
//QAbstractItemModel *sourceModel;
//TreeSortFilter is a subclass of QSortFilterProxyModel to search through children
TreeSortFilter *proxyModel = new TreeSortFilter(this);
proxyModel->setSourceModel(sourceModel);
ui.treeWidget->QTreeView::setModel(proxyModel);
QRegExp rx(filtr, Qt::CaseInsensitive);
proxyModel->setFilterRegExp(rx);
ui.treeWidget->QTreeView::setModel(proxyModel);
}

using qDebug() I can see that it's crashing on "selection.at(i)->text(0)". Also what I noticed is that when I check qDebug() << selection.size() before filtering it does indicate the normal number of selected items but after I use the filter, it only counts the parents of each children selected. so if I select 10 children from 3 differents parents selection.size() will only return 3.

Any idea what's wrong?

thanx in advance

Pat

gfunk
13th July 2006, 19:40
I don't see anything wrong (but I'm just novice). Perhaps we can see the TreeSortFilter class? What is value of i when selection.at(i)->text(0) causes crash?

patcito
14th July 2006, 02:54
Check out kdenonbeta/kdom/patternist/kxqts/view/TreeSortFilter.{cpp,h}

http://patternist.sourceforge.net/documentation/API/group__KXQTS.html