PDA

View Full Version : read access violation err. when assembling QSortFilterProxy and QIdentityProxy Models



Guett_31
8th August 2013, 03:49
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:

QFileSystemModel * fileSystemModel = new QFileSystemModel;
fileSystemModel->setRootPath("C:/");
ui->scriptFileView->setModel(fileSystemModel);
ui->scriptFileView->setRootIndex(fileSystemModel->index("C:/"));
scriptFileView is an instance of the FileSysSelectView Class below:

FileSysSelectView::FileSysSelectView(QWidget *parent) : QTreeView(parent),
m_prox1(new QSortFilterProxyModel()),
m_prox2(new QIdentityProxyModel()),
m_prox3(new QIdentityProxyModel())
{
}

void FileSysSelectView::setRootIndex(const QModelIndex & index)
{
QModelIndex proxIdx = m_prox1->mapFromSource(index);
proxIdx = m_prox2->mapFromSource(proxIdx);
proxIdx = m_prox3->mapFromSource(proxIdx);
QTreeView::setRootIndex(proxIdx);
}

void FileSysSelectView::setModel(QFileSystemModel * model)
{
m_sourceModel = model;
m_prox1->setSourceModel(m_sourceModel);
m_prox2->setSourceModel(m_prox1);
m_prox3->setSourceModel(m_prox2);
QTreeView::setModel(m_prox3);
}
These are the only methodes I have overloaded from QTreeView.

Santosh Reddy
8th August 2013, 11:35
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();

Guett_31
11th August 2013, 18:08
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:

QFileSystemModel * fileSystemModel = new QFileSystemModel;
fileSystemModel->setRootPath("C:/");
ui->scriptFileView->setModel(fileSystemModel);
//ui->scriptFileView->setRootIndex("C:/");

Guett_31
13th August 2013, 02:42
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.

#include <QApplication>
#include <QtGui>
#include <QTreeView>
#include <QFileSystemModel>
#include <QIdentityProxyModel>
#include <QSortFilterProxyModel>

int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget mywindow;
mywindow.setFixedSize(400,400);

QTreeView * myView = new QTreeView(& mywindow);
myView->setFixedSize(400,400);

QFileSystemModel * sourceModel = new QFileSystemModel();
QSortFilterProxyModel * proxy1 = new QSortFilterProxyModel();
QIdentityProxyModel * proxy2 = new QIdentityProxyModel();

sourceModel->setRootPath("C:/");

proxy1->setSourceModel(sourceModel);
proxy2->setSourceModel(proxy1);

myView->setModel(proxy2);

mywindow.show();
return app.exec();
}

ChrisW67
13th August 2013, 06:20
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:


#include <QtGui>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QTreeView myView;
QFileSystemModel * sourceModel = new QFileSystemModel(&myView);
QSortFilterProxyModel * proxy1 = new QSortFilterProxyModel(&myView);
QIdentityProxyModel * proxy2 = new QIdentityProxyModel(&myView);

sourceModel->setRootPath("/");

proxy1->setSourceModel(sourceModel);
proxy2->setSourceModel(proxy1);

myView.setModel(proxy2);
myView.show();
return app.exec();
}

Built on Linux 64-bit Qt 4.8.4

The backtrace is entirely inside Qt's code:


(gdb) run
Starting program: /tmp/uu/uu
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[New Thread 0x7fffee39c700 (LWP 6195)]
[New Thread 0x7fffed18b700 (LWP 6196)]
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource
QSortFilterProxyModel: index from wrong model passed to mapFromSource

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff788de1d in QSortFilterProxyModel::parent(QModelIndex const&) const () from /usr/lib64/qt4/libQtGui.so.4
(gdb) bt
#0 0x00007ffff788de1d in QSortFilterProxyModel::parent(QModelIndex const&) const ()
from /usr/lib64/qt4/libQtGui.so.4
#1 0x00007ffff78234b0 in QIdentityProxyModel::parent(QModelIndex const&) const () from /usr/lib64/qt4/libQtGui.so.4
#2 0x00007ffff6dc10f3 in QPersistentModelIndex::parent() const () from /usr/lib64/qt4/libQtCore.so.4
#3 0x00007ffff785e419 in QItemSelectionModel::isSelected(QModelIndex const&) const ()
from /usr/lib64/qt4/libQtGui.so.4
#4 0x00007ffff7849549 in QTreeView::drawRow(QPainter*, QStyleOptionViewItem const&, QModelIndex const&) const ()
from /usr/lib64/qt4/libQtGui.so.4
#5 0x00007ffff784c718 in QTreeView::drawTree(QPainter*, QRegion const&) const () from /usr/lib64/qt4/libQtGui.so.4
#6 0x00007ffff784cf50 in QTreeView::paintEvent(QPaintEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#7 0x00007ffff73573ee in QWidget::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#8 0x00007ffff76f3696 in QFrame::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#9 0x00007ffff7807aab in QAbstractItemView::viewportEvent(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#10 0x00007ffff784e865 in QTreeView::viewportEvent(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#11 0x00007ffff6dcdf28 in QCoreApplicationPrivate::sendThroughObjectEventFil ters(QObject*, QEvent*) ()
from /usr/lib64/qt4/libQtCore.so.4
#12 0x00007ffff7306bcf in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#13 0x00007ffff730b9d3 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#14 0x00007ffff6dcdd9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#15 0x00007ffff7352f26 in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#16 0x00007ffff7353b9f in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#17 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#18 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#19 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#20 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#21 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#22 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#23 0x00007ffff7353927 in QWidgetPrivate::paintSiblingsRecursive(QPaintDevic e*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#24 0x00007ffff7352c5c in QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) () from /usr/lib64/qt4/libQtGui.so.4
#25 0x00007ffff751eae2 in ?? () from /usr/lib64/qt4/libQtGui.so.4
#26 0x00007ffff7349c80 in QWidgetPrivate::syncBackingStore() () from /usr/lib64/qt4/libQtGui.so.4
#27 0x00007ffff7357b36 in QWidget::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#28 0x00007ffff76f3696 in QFrame::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
---Type <return> to continue, or q <return> to quit---
#29 0x00007ffff77758eb in QAbstractScrollArea::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#30 0x00007ffff781228b in QAbstractItemView::event(QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#31 0x00007ffff7306c04 in QApplicationPrivate::notify_helper(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#32 0x00007ffff730b9d3 in QApplication::notify(QObject*, QEvent*) () from /usr/lib64/qt4/libQtGui.so.4
#33 0x00007ffff6dcdd9c in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib64/qt4/libQtCore.so.4
#34 0x00007ffff6dd164a in QCoreApplicationPrivate::sendPostedEvents(QObject* , int, QThreadData*) ()
from /usr/lib64/qt4/libQtCore.so.4
#35 0x00007ffff6dfca93 in ?? () from /usr/lib64/qt4/libQtCore.so.4
#36 0x00007ffff65683f2 in g_main_context_dispatch () from /usr/lib64/libglib-2.0.so.0
#37 0x00007ffff6568738 in ?? () from /usr/lib64/libglib-2.0.so.0
#38 0x00007ffff65687f4 in g_main_context_iteration () from /usr/lib64/libglib-2.0.so.0
#39 0x00007ffff6dfcebf in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib64/qt4/libQtCore.so.4
#40 0x00007ffff73a96fe in ?? () from /usr/lib64/qt4/libQtGui.so.4
#41 0x00007ffff6dcc8d2 in QEventLoop::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib64/qt4/libQtCore.so.4
#42 0x00007ffff6dccb27 in QEventLoop::exec(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib64/qt4/libQtCore.so.4
#43 0x00007ffff6dd1945 in QCoreApplication::exec() () from /usr/lib64/qt4/libQtCore.so.4
#44 0x0000000000400d92 in main ()
(gdb)


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.