Map proxy model to source model index unexpected behaviour
<p>There is a <code>QTableview</code> that has a <code>QSortFilterProxyModel</code> as its data backend. Each row in the table has a unique ID, but only in the source model (column 0), not in the proxy model. I need to iterate over all the rows of the table and find the row with a specific ID to identify a row to select. However <code>mapToSource</code> fails, as soon as I change the current index that I iterate over. Error: <code>QSortFilterProxyModel: index from wrong model passed to mapToSource</code>. </p>

<p>This behaviour is really odd because just before the for loop I do check if mapToSource works, and it does!</p>

<p>What Qt complains about is <code>if (proxy_index.model() != q_func()) {...}</code>, but I do not see why <code>q_func()</code> should all of a sudden return a different model...</p>

<pre><code>    QModelIndex indexOfItem;

    QAbstractItemView *itemView = this-&gt;viewHandler()-&gt;currentView();
    QSortFilterProxyModel *m = static_cast&lt;QSortFilterProxyModel*&gt;( itemView-&gt;model() );
    qDebug()&lt;&lt;"proxy model:"&lt;&lt;m;
    qDebug()&lt;&lt;"source model:"&lt;&lt;m-&gt;sourceModel();
    int idColumn = static_cast&lt;int&gt;(MyEnums::ResourceDataFields::Common_uuid);

    QModelIndex startIdx = itemView-&gt;currentIndex();
    qDebug()&lt;&lt;"start index proxy model:" &lt;&lt; startIdx;
    qDebug()&lt;&lt;"start index source model:" &lt;&lt; m-&gt;mapToSource(startIdx); // &lt;== OK!

    for ( int row = 0; row &lt; m-&gt;rowCount(); ++row ){

          // Get index of next row to compare:
//        QModelIndex proxyIndex = m-&gt;index( row, 0 );
//        QModelIndex proxyIndex = startIdx.sibling( row, startIdx.column() );
        QModelIndex proxyIndex = startIdx.model()-&gt;index( row, startIdx.column(), startIdx.parent() );
        qDebug()&lt;&lt;"proxy index:"&lt;&lt;proxyIndex; // &lt;== seems OK!

          // Map to parent model, to get ID column:
        QModelIndex sourceRow = m-&gt;mapToSource( proxyIndex ); // &lt;== Error!

        QModelIndex idx = sourceRow.sibling( sourceRow.row(), idColumn );
        QString id = m-&gt;data( idx ).toString();
        qDebug()&lt;&lt;"id:"&lt;&lt;id;
        if ( id == uuid ){
            indexOfItem = m-&gt;index( row, 0 );
            break;
        }
    }

    if ( indexOfItem.isValid() ){
        qDebug()&lt;&lt;"Setting current index:"&lt;&lt;indexOfItem;
        itemView-&gt;setCurrentIndex( indexOfItem );
        itemView-&gt;scrollTo( indexOfItem );
    }
</code></pre>