PDA

View Full Version : Segfault using QSortFilterProxeModel and QTreeView



Cucumber
7th December 2010, 05:29
Hello there,

I am using TreeItem and TreeModel classes from Qt SimpleTreeModel example, except for one method that is called constantly at rate of one per second:

void TreeModel::addItem()
{
TreeItem* treeItem = new TreeItem;
rootItem->appendChild(treeItem);

emit layoutChanged();
}
As well I am using QSortFilterProxyModel following way:

model = new TreeModel;

proxyModel = new QSortFilterProxyModel;
proxyModel->setSourceModel(model);
proxyModel->setDynamicSortFilter(true);

treeView = new QTreeView;
treeView->setModel(proxyModel);
I have a stupid segfault and really need some help. Part of backtrace is below:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x000000000000000a in QSortFilterProxyModelPrivate:: proxy_to_source ()
(gdb) bt
#0 0x000000000000000a in QSortFilterProxyModelPrivate:: proxy_to_source ()
#1 0x000000000000000b in QSortFilterProxyModel::mapToSource ()

Don't know will it help or no, but segfault repeats almost always after switching from fullscreen to normal.

Where is the problem (imo, it is after layoutChanged() signal is emitted) and how can I fix it?

I've read almost the whole Google and found some relative problems where it was advised to reimplement mapToSource() and mapFromSource(). But I can't make it right due to lack of skills.

Really looking forward for your help. Big thanks in advance!

franz
7th December 2010, 06:46
Would it be an idea to properly use beginInsertRows() and endInsertRows() instead of emitting a custom layoutChanged() signal? Maybe that causes the issue in the first place.

Cucumber
7th December 2010, 13:44
Would it be an idea to properly use beginInsertRows() and endInsertRows() instead of emitting a custom layoutChanged() signal? Maybe that causes the issue in the first place.
Thank you soo much! You can't even imagine, how have you helped me!
The working code for now is below:

void TreeModel::addItem()
{
TreeItem* treeItem = new TreeItem;
beginInsertRows(QModelIndex(), rootItem->childCount(), rootItem->childCount());
rootItem->appendChild(treeItem);
endInsertRows();
}