[Qt-interest] Qt MVC Questions

Sean Harmer sean.harmer at maps-technology.com
Mon Sep 21 10:23:20 CEST 2009


On Sunday 20 Sep 2009 23:59:20 Willy P wrote:
> Sean,
> Thanks for writing back.  Late last night I came across the ProxyModel
> classes.  I inherited from QSortFilterProxyModel and am attempting to
> create mapTo / mapFrom source functions that, for starters, simply
> pass the the values back and forth with no modification.  It is not
> working at all:
>
>
> 	QModelIndex ReducedTreeModel::mapFromSource( const QModelIndex & source )
> const {
> 		qDebug() << "from Source" << source.row() << source.column() <<
> source.internalId();
> 		return createIndex( source.row(), source.column(), ( quint32
> )source.internalId() );
> 	}
>
>
>
> 	QModelIndex ReducedTreeModel::mapToSource( const QModelIndex& proxy )
> const {
> 		qDebug() << "to Source" << proxy.row() << proxy.column() <<
> proxy.internalId();
> 		return (sourceModel()&&proxy.isValid())
> 				? sourceModel()->index(proxy.row(), proxy.column(), proxy.parent())
>
> 				: QModelIndex();
>
> 	}
>
>
> Can you tell me what I'm doing wrong here?  It's crashing when an
> absolutely junk value comes into mapToSource for proxy.internalId().
>
> Thanks again...

I am guessing that it is crashing in the index() function of your source 
model. You need to ensure that the parent index is valid in your index 
function.

HTH,

Sean



More information about the Qt-interest-old mailing list