Results 1 to 5 of 5

Thread: QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

  1. #1
    Join Date
    Aug 2008
    Posts
    39
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

    So this works when I don't use a QSortFilterProxyModel but when I make QTreeView use a QSortFilterProxyModel, the compiled code seg faults...

    Qt Code:
    1. QTreeView *treeView = new QTreeView();
    2. QDirModel *dirModel = new QDirModel();
    3.  
    4. proxyDirModel->setSourceModel(dirModel);
    5. treeView->setModel(proxyDirModel);
    6.  
    7. // I have tried it both of these ways:
    8. treeView->setRootIndex(dirModel->index("/"));
    9. //treeView->setRootIndex(treeProxyModel->sourceModel()->index("/"));
    To copy to clipboard, switch view to plain text mode 

    How can I make this work? Right now it seems like having two QDirModels works without problems when I use one dirmodel and try to do this the right way I run into lots of problems and not a lot of good documentation...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

    Which Qt version do you use?

  3. The following user says thank you to jacek for this useful post:

    killerwookie99 (16th August 2008)

  4. #3
    Join Date
    Aug 2008
    Posts
    39
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

    Upgraded to 4.4.1 a few days back...

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

    Quote Originally Posted by killerwookie99 View Post
    treeView->setModel(proxyDirModel);

    // I have tried it both of these ways:
    treeView->setRootIndex(dirModel->index("/"));
    //treeView->setRootIndex(treeProxyModel->sourceModel()->index("/"));
    You can't give dirModel's indices to the treeView, because it operates on treeProxyModel.

    Use:
    Qt Code:
    1. QModelIndex idx = treeProxyModel->mapFromSource( dirModel->index("/") );
    2. treeView->setRootIndex( idx );
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to jacek for this useful post:

    killerwookie99 (16th August 2008)

  7. #5
    Join Date
    Aug 2008
    Posts
    39
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTreeModel->setRootIndex when using QSortFilterProxyModel segfaults

    Sweet thank you!

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.