How to search through a (filtered) QSortFilterProxyModel in Qt (C++)?
<p>I have a working filter function (<code>filterAcceptsRow</code>) that filters a hierarchical <code>QTreeView</code> based on the first column (index0). I need to connect a search <code>QLineEdit</code> in order to let the user search trough the (filtered) <code>QTreeView</code>. I am not sure how to add a search algorithm to this function. Can anyone help me figuring out? The search algorithm should search for a <code>QString</code> in all 5 columns (index0-index4).</p>

<p><strong>My filter function:</strong></p>

<pre><code>bool ProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &amp;sourceParent) const
{
    QModelIndex index0 = sourceModel()-&gt;index(sourceRow, 0, sourceParent);
    QModelIndex index1 = sourceModel()-&gt;index(sourceRow, 1, sourceParent);
    QModelIndex index2 = sourceModel()-&gt;index(sourceRow, 2, sourceParent);
    QModelIndex index3 = sourceModel()-&gt;index(sourceRow, 3, sourceParent);
    QModelIndex index4 = sourceModel()-&gt;index(sourceRow, 4, sourceParent);

    if (m_filterEnabled)
    {
        foreach (const QString &amp;row, rows)
        {
            if (sourceModel()-&gt;data(index0).toString().contains(row) &amp;&amp; m_shownRow)
                return true; //element should be shown
            else if (sourceModel()-&gt;data(index0).toString().contains(row) &amp;&amp; !m_shownRow)
                return false; //element should NOT be shown
        }
        if (m_shownRow)
            return false;
        else
            return true;
    } else {
        return true; //no filter -&gt; show everything
    }   
}
</code></pre>