Results 1 to 3 of 3

Thread: selectedIems() not working with QSortFilterProxyModel

  1. #1
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default selectedIems() not working with QSortFilterProxyModel

    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
    Last edited by jacek; 13th July 2006 at 11:46. Reason: post date has been changed to restore thread order

  2. #2
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: selectedIems() not working with QSortFilterProxyModel

    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?
    Software Engineer



  3. #3
    Join Date
    Jan 2006
    Posts
    46
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: selectedIems() not working with QSortFilterProxyModel

    Check out kdenonbeta/kdom/patternist/kxqts/view/TreeSortFilter.{cpp,h}

    http://patternist.sourceforge.net/do...up__KXQTS.html

Similar Threads

  1. Replies: 1
    Last Post: 11th June 2006, 22:25
  2. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02
  3. Signals/Slots stopped working
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2006, 21:11
  4. Working with Date type in database applications
    By kolach in forum Qt Programming
    Replies: 13
    Last Post: 25th January 2006, 14:20
  5. QSettings - beginReadArray not working
    By Mike in forum Qt Programming
    Replies: 7
    Last Post: 9th January 2006, 21:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.