Results 1 to 5 of 5

Thread: read access violation err. when assembling QSortFilterProxy and QIdentityProxy Models

  1. #1
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    14
    Thanked 7 Times in 7 Posts

    Default read access violation err. when assembling QSortFilterProxy and QIdentityProxy Models

    Hi,
    I’m trying to put several proxy models in series and I get an exception with a read access violation. I don’t get any trace back for this error, so it makes it very difficult for me the figure out what’s going on.
    Below is a very simplified version of my code that shows the problem:
    Qt Code:
    1. QFileSystemModel * fileSystemModel = new QFileSystemModel;
    2. fileSystemModel->setRootPath("C:/");
    3. ui->scriptFileView->setModel(fileSystemModel);
    4. ui->scriptFileView->setRootIndex(fileSystemModel->index("C:/"));
    To copy to clipboard, switch view to plain text mode 
    scriptFileView is an instance of the FileSysSelectView Class below:
    Qt Code:
    1. FileSysSelectView::FileSysSelectView(QWidget *parent) : QTreeView(parent),
    2. m_prox1(new QSortFilterProxyModel()),
    3. m_prox2(new QIdentityProxyModel()),
    4. m_prox3(new QIdentityProxyModel())
    5. {
    6. }
    7.  
    8. void FileSysSelectView::setRootIndex(const QModelIndex & index)
    9. {
    10. QModelIndex proxIdx = m_prox1->mapFromSource(index);
    11. proxIdx = m_prox2->mapFromSource(proxIdx);
    12. proxIdx = m_prox3->mapFromSource(proxIdx);
    13. QTreeView::setRootIndex(proxIdx);
    14. }
    15.  
    16. void FileSysSelectView::setModel(QFileSystemModel * model)
    17. {
    18. m_sourceModel = model;
    19. m_prox1->setSourceModel(m_sourceModel);
    20. m_prox2->setSourceModel(m_prox1);
    21. m_prox3->setSourceModel(m_prox2);
    22. QTreeView::setModel(m_prox3);
    23. }
    To copy to clipboard, switch view to plain text mode 
    These are the only methodes I have overloaded from QTreeView.

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    3
    Thanked 453 Times in 435 Posts
    Wiki edits
    15

    Default Re: read access violation err. when assembling QSortFilterProxy and QIdentityProxy Mo

    In FileSysSelectView::setRootIndex() you are geting the QModelIndex from the source QFileSystemModel, it is not garanteed that the path is completely loaded and QModelIndex returned may be invalid. So wait for the directoryLoaded() signal and then call FileSysSelectView::setRootIndex();
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    14
    Thanked 7 Times in 7 Posts

    Default Re: read access violation err. when assembling QSortFilterProxy and QIdentityProxy Mo

    Thank you Santosh. I don't think the problem is related to FileSysSelectView::setRootIndex() because the same problem occurs when I comment out the function's call:
    Qt Code:
    1. QFileSystemModel * fileSystemModel = new QFileSystemModel;
    2. fileSystemModel->setRootPath("C:/");
    3. ui->scriptFileView->setModel(fileSystemModel);
    4. //ui->scriptFileView->setRootIndex("C:/");
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2013
    Location
    San Diego
    Posts
    37
    Qt products
    Qt4 Qt5
    Platforms
    Windows
    Thanks
    14
    Thanked 7 Times in 7 Posts

    Default Re: read access violation err. when assembling QSortFilterProxy and QIdentityProxy Mo

    I could make the problem even more obvious in the piece of code below. (It can be compiled as-is)
    It does not even require 3 proxies. A QSortFilterProxyModel and a QIdentityProxyModel in series over a QFileSystemModel is enough to reproduce this issue.
    After clicking quickly in the Tree view a few times to expand folders in order to stress the software, I get the same read access violation error.
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3. #include <QTreeView>
    4. #include <QFileSystemModel>
    5. #include <QIdentityProxyModel>
    6. #include <QSortFilterProxyModel>
    7.  
    8. int main(int argc, char *argv[])
    9. {
    10. QApplication app(argc, argv);
    11.  
    12. QWidget mywindow;
    13. mywindow.setFixedSize(400,400);
    14.  
    15. QTreeView * myView = new QTreeView(& mywindow);
    16. myView->setFixedSize(400,400);
    17.  
    18. QFileSystemModel * sourceModel = new QFileSystemModel();
    19. QIdentityProxyModel * proxy2 = new QIdentityProxyModel();
    20.  
    21. sourceModel->setRootPath("C:/");
    22.  
    23. proxy1->setSourceModel(sourceModel);
    24. proxy2->setSourceModel(proxy1);
    25.  
    26. myView->setModel(proxy2);
    27.  
    28. mywindow.show();
    29. return app.exec();
    30. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: read access violation err. when assembling QSortFilterProxy and QIdentityProxy Mo

    The error message is fairly explicit. It only occurs for me if the identity model is chained off the sort filter model. I could not produce it the other way around or with the sort/filter or identity model alone.

    Here is my minimal code:
    Qt Code:
    1. #include <QtGui>
    2. int main(int argc, char *argv[])
    3. {
    4. QApplication app(argc, argv);
    5. QTreeView myView;
    6. QFileSystemModel * sourceModel = new QFileSystemModel(&myView);
    7. QIdentityProxyModel * proxy2 = new QIdentityProxyModel(&myView);
    8.  
    9. sourceModel->setRootPath("/");
    10.  
    11. proxy1->setSourceModel(sourceModel);
    12. proxy2->setSourceModel(proxy1);
    13.  
    14. myView.setModel(proxy2);
    15. myView.show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    Built on Linux 64-bit Qt 4.8.4

    The backtrace is entirely inside Qt's code:
    Qt Code:
    1. (gdb) run
    2. Starting program: /tmp/uu/uu
    3. warning: Could not load shared library symbols for linux-vdso.so.1.
    4. Do you need "set solib-search-path" or "set sysroot"?
    5. [Thread debugging using libthread_db enabled]
    6. Using host libthread_db library "/lib64/libthread_db.so.1".
    7. [New Thread 0x7fffee39c700 (LWP 6195)]
    8. [New Thread 0x7fffed18b700 (LWP 6196)]
    9. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    10. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    11. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    12. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    13. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    14. QSortFilterProxyModel: index from wrong model passed to mapFromSource
    15.  
    16. Program received signal SIGSEGV, Segmentation fault.
    17. 0x00007ffff788de1d in QSortFilterProxyModel::parent(QModelIndex const&) const () from /usr/lib64/qt4/libQtGui.so.4
    18. (gdb) bt
    19. #0 0x00007ffff788de1d in QSortFilterProxyModel::parent(QModelIndex const&) const ()
    20. from /usr/lib64/qt4/libQtGui.so.4
    21. #1 0x00007ffff78234b0 in QIdentityProxyModel::parent(QModelIndex const&) const () from /usr/lib64/qt4/libQtGui.so.4
    22. #2 0x00007ffff6dc10f3 in QPersistentModelIndex::parent() const () from /usr/lib64/qt4/libQtCore.so.4
    23. #3 0x00007ffff785e419 in QItemSelectionModel::isSelected(QModelIndex const&) const ()
    24. from /usr/lib64/qt4/libQtGui.so.4
    25. #4 0x00007ffff7849549 in QTreeView::drawRow(QPainter*, QStyleOptionViewItem const&, QModelIndex const&) const ()
    26. from /usr/lib64/qt4/libQtGui.so.4
    27. #5 0x00007ffff784c718 in QTreeView::drawTree(QPainter*, QRegion const&) const () from /usr/lib64/qt4/libQtGui.so.4
    28. #6 0x00007ffff784cf50 in QTreeView::paintEvent(QPaintEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    29. #7 0x00007ffff73573ee in QWidget::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    30. #8 0x00007ffff76f3696 in QFrame::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    31. #9 0x00007ffff7807aab in QAbstractItemView::viewportEvent(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    32. #10 0x00007ffff784e865 in QTreeView::viewportEvent(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    33. #11 0x00007ffff6dcdf28 in QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject*, QEvent*) ()
    34. from /usr/lib64/qt4/libQtCore.so.4
    35. #12 0x00007ffff7306bcf in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    36. #13 0x00007ffff730b9d3 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    37. #14 0x00007ffff6dcdd9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
    38. #15 0x00007ffff7352f26 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    39. #16 0x00007ffff7353b9f in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    40. #17 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    41. #18 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    42. #19 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    43. #20 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    44. #21 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    45. #22 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    46. #23 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    47. #24 0x00007ffff7352c5c in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
    48. #25 0x00007ffff751eae2 in ?? () from /usr/lib64/qt4/libQtGui.so.4
    49. #26 0x00007ffff7349c80 in QWidgetPrivate::syncBackingStore() () from /usr/lib64/qt4/libQtGui.so.4
    50. #27 0x00007ffff7357b36 in QWidget::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    51. #28 0x00007ffff76f3696 in QFrame::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    52. ---Type <return> to continue, or q <return> to quit---
    53. #29 0x00007ffff77758eb in QAbstractScrollArea::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    54. #30 0x00007ffff781228b in QAbstractItemView::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    55. #31 0x00007ffff7306c04 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    56. #32 0x00007ffff730b9d3 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
    57. #33 0x00007ffff6dcdd9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
    58. #34 0x00007ffff6dd164a in QCoreApplicationPrivate::sendPostedEvents(QObject*, int, QThreadData*) ()
    59. from /usr/lib64/qt4/libQtCore.so.4
    60. #35 0x00007ffff6dfca93 in ?? () from /usr/lib64/qt4/libQtCore.so.4
    61. #36 0x00007ffff65683f2 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
    62. #37 0x00007ffff6568738 in ?? () from /usr/lib64/libglib-2.0.so.0
    63. #38 0x00007ffff65687f4 in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
    64. #39 0x00007ffff6dfcebf in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
    65. from /usr/lib64/qt4/libQtCore.so.4
    66. #40 0x00007ffff73a96fe in ?? () from /usr/lib64/qt4/libQtGui.so.4
    67. #41 0x00007ffff6dcc8d2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
    68. from /usr/lib64/qt4/libQtCore.so.4
    69. #42 0x00007ffff6dccb27 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
    70. from /usr/lib64/qt4/libQtCore.so.4
    71. #43 0x00007ffff6dd1945 in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
    72. #44 0x0000000000400d92 in main ()
    73. (gdb)
    To copy to clipboard, switch view to plain text mode 

    Something is getting its model or internal pointers confused. I would report a bug at this point. Having come across QIdentityProxyModel bugs myself, and it being the newer code, I'd be looking here first.
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

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

    Guett_31 (13th August 2013)

Similar Threads

  1. Access violation using QTableWidget
    By mchome in forum Newbie
    Replies: 2
    Last Post: 4th September 2012, 08:39
  2. Dynamic graph, access read violation
    By Momhaing in forum Qwt
    Replies: 1
    Last Post: 7th July 2011, 14:40
  3. Access violation -- qobject.cpp
    By willief in forum Newbie
    Replies: 9
    Last Post: 14th February 2011, 23:55
  4. Access Violation with VS2008
    By Takatschio in forum Qt Programming
    Replies: 3
    Last Post: 19th August 2010, 10:16
  5. QModelIndexList access reading violation
    By Daxos in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2010, 09:32

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
  •  
Qt is a trademark of The Qt Company.