Results 1 to 13 of 13

Thread: QSortProxyFilterModel invalidation crashes

  1. #1
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSortProxyFilterModel invalidation crashes

    Dear friends,

    I've faced the next problem. There is a chain of QSortFilterProxyModels in my application:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. ....
    3. m1 = new MyFilterModel(this);
    4. m1->setSourceModel(new MyTreeModel(this));
    5. m1->setType(E_SHOW_ALL);
    6.  
    7. m2 = new MyFilterModel(this);
    8. m2->setSourceModel(m1);
    9. m2->setType(E_SHOW_ALL);
    10.  
    11. m3 = new MyFilterModel(this);
    12. m3->setSourceModel(m2);
    13. m3->setType(E_SHOW_ALL);
    14.  
    15. ui->treeView->setModel(m3);
    16. ....
    17. }
    To copy to clipboard, switch view to plain text mode 
    , MyFilterModel implements custom filtering (overrides QSortFilterProxyModel::filterAcceptRows()).

    Now I want to change filtering parameter m1 uses:

    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. m1->setType(E_SHOW_FEW); // it only
    4. // changes m1->m_parameter value which
    5. // one uses inside m1->filterAcceptRows()
    6.  
    7. m1->invalidate(); // crash :(
    8. }
    To copy to clipboard, switch view to plain text mode 
    , m1->invalidate() call crashes the application.

    Could you, guys, please, help me to figure out what am I doing wrong?

    Platform: Windows Vista;
    Qt version: 4.6.0 (from SDK);
    Compiler: MinGW

    P.S. I also tried to call "invalidateFilter()" instead of "invalidate()", it works fine, but I can't use it: the production version of our application uses old version of Qt (4.5) and it seems that there was a bug in invalidateFilter(): sometimes it doesn't show some rows (by the way if I call invalidateFilter() twice everything works as a charm)

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortProxyFilterModel invalidation crashes

    What if you substitute MyTreeModel with QStandardItemModel? Does it still crash?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSortProxyFilterModel invalidation crashes

    If setType() changes internal values that are only used in filterAcceptsRows() the invalidateFilter() would be the correct thing to call. I didn't see a related bug in the tracker. Do you have a bug number?

    Storing pointers to things that invalidate() might throw away is just one of a multitude of things that could be going wrong. Running in a debugger should fairly quickly tell you where your program dies. If you still cannot fathom it then it would help if you could show us what you are doing in the setType() and filterAcceptsRows() methods.

  4. #4
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    ChrisW67, wysota, thank you very much for your help.

    Quote Originally Posted by wysota View Post
    What if you substitute MyTreeModel with QStandardItemModel? Does it still crash?
    No, it's not. Everything works fine. But it is a sandbox, I can't replace QAbstractItemModel with QStandardItemModel in the real application, it's too expensive.

    Quote Originally Posted by ChrisW67 View Post
    If setType() changes internal values that are only used in filterAcceptsRows() the invalidateFilter() would be the correct thing to call. I didn't see a related bug in the tracker. Do you have a bug number?
    No, I haven't.

    Let me describe the situation in more details:
    I have an application with QTreeView, which uses chain of QSortFilterProxyModel (3 filters) to display data from the model. But in my code QSortFilterProxyModel::invalidateFilter() behave itself in very strange way: sometimes it misses rows, no matter which filter model calls it... I don't know if it is a bug in my code (3 days of debug already... oh my head) or in the Qt (4.5), but this:
    Qt Code:
    1. this->invalidateFilter();
    2. this->invalidateFilter();
    To copy to clipboard, switch view to plain text mode 
    works just great. If the chain contains only 2 filters, then:
    Qt Code:
    1. this->invalidate();
    To copy to clipboard, switch view to plain text mode 
    works fine too. But it crashes when there are 3 filters.

    So I was trying to reproduce the problem in sandbox and I succeed with crash.

    Quote Originally Posted by ChrisW67 View Post
    Storing pointers to things that invalidate() might throw away is just one of a multitude of things that could be going wrong. Running in a debugger should fairly quickly tell you where your program dies. If you still cannot fathom it then it would help if you could show us what you are doing in the setType() and filterAcceptsRows() methods.
    That's funny, this code crashes too:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. m1 = new QSortFilterProxyModel(this);
    8. m1->setSourceModel(new MyTreeModel(NULL));
    9.  
    10. m2 = new QSortFilterProxyModel(this);
    11. m2->setSourceModel(m1);
    12.  
    13. m3 = new QSortFilterProxyModel(this);
    14. m3->setSourceModel(m2);
    15.  
    16. ui->treeView->setModel(m3);
    17. ui->treeView->expandAll();
    18. }
    19.  
    20. void MainWindow::on_pushButton_clicked()
    21. {
    22. m1->invalidate(); // crash
    23. ui->treeView->expandAll();
    24. }
    To copy to clipboard, switch view to plain text mode 
    , but this works fine:
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6.  
    7. m1 = new QSortFilterProxyModel(this);
    8. m1->setSourceModel(new MyTreeModel(NULL));
    9.  
    10. m2 = new QSortFilterProxyModel(this);
    11. m2->setSourceModel(m1);
    12.  
    13. //m3 = new QSortFilterProxyModel(this);
    14. //m3->setSourceModel(m2);
    15.  
    16. ui->treeView->setModel(/*m3*/m2);
    17. ui->treeView->expandAll();
    18.  
    19.  
    20. }
    21.  
    22. void MainWindow::on_pushButton_clicked()
    23. {
    24. m1->invalidate(); // works!
    25. ui->treeView->expandAll();
    26. }
    To copy to clipboard, switch view to plain text mode 



    The stacktrace, MyTreeModel's implementation and the whole sandbox project are attached. Please let me know if there's anything else I can provide.
    Attached Files Attached Files
    Last edited by stillwaiting; 13th September 2010 at 14:56.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortProxyFilterModel invalidation crashes

    Quote Originally Posted by stillwaiting View Post
    No, it's not. Everything works fine. But it is a sandbox, I can't replace QAbstractItemModel with QStandardItemModel in the real application, it's too expensive.
    Nobody said you should. If it works with the standard item model then it is most probable that the error is in your model class and not the proxy.

    Take the model checker from Qt labs and test your model implementation.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    Quote Originally Posted by wysota View Post
    Nobody said you should. If it works with the standard item model then it is most probable that the error is in your model class and not the proxy.

    Take the model checker from Qt labs and test your model implementation.
    I checked it: a few asserts were raised in my code (not in the model checker). I replaced them with "if"s and all tests were successully passed. But it still crashes

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortProxyFilterModel invalidation crashes

    For me your parent() implementation is incorrect or at least weird I would get rid of all the asserts too (you probably already did that).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #8
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    Quote Originally Posted by wysota View Post
    For me your parent() implementation is incorrect or at least weird I would get rid of all the asserts too (you probably already did that).
    This is just a sample model from my sandbox . I can't find any errors, QTreeView shows it properly, modelchecker shows no errors too. It even works with two proxy models in the chain. I can't understand what is wrong with the 3rd one and why it crashes. I just can't.

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortProxyFilterModel invalidation crashes

    I'm not getting a crash for your sandbox app. Or maybe I just don't know how to replicate it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    Quote Originally Posted by wysota View Post
    I'm not getting a crash for your sandbox app. Or maybe I just don't know how to replicate it.
    Wysota, thank you for your interest , I really appreciate it.

    Here's the project which I've just checked. It crashes when I click the only enabled button: sometimes it crashes after the 1st click, sometimes I have to click up to 10 times. The debug version raises the assert somewhere deep inside the QSortFilterProxyModel's implementation.

    I am able to reproduce this on my environment:
    OS: Windows Vista;
    Qt: 4.6.0, Compiler: MinGW; or
    Qt: 4.5.1, Compiler: cl from M$VC 2005
    Attached Files Attached Files

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QSortProxyFilterModel invalidation crashes

    Doesn't crash, sorry. Linux/x86, Qt4.7.0 snapshot. I do experience some temporary slowdowns after clicking the button many times however.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    stillwaiting (13th September 2010)

  13. #12
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    Quote Originally Posted by wysota View Post
    Doesn't crash, sorry. Linux/x86, Qt4.7.0 snapshot. I do experience some temporary slowdowns after clicking the button many times however.
    That's sad

  14. #13
    Join Date
    Sep 2010
    Posts
    18
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSortProxyFilterModel invalidation crashes

    Anybody?...

Similar Threads

  1. Application crashes when it has a particular name
    By hunsrus in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2010, 20:50
  2. Application crashes
    By waynew in forum Newbie
    Replies: 1
    Last Post: 2nd November 2009, 10:31
  3. app crashes again
    By sophister in forum Qt Programming
    Replies: 7
    Last Post: 15th June 2009, 10:01
  4. My application crashes
    By sophister in forum Qt Programming
    Replies: 13
    Last Post: 27th April 2009, 07:39
  5. Uic3 crashes...
    By amcdaniel in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2007, 22:06

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.