Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get final QModelIndex in a chain of QAbstractProxyIndex
Forum Updated to NodeBB v4.3 + New Features

Get final QModelIndex in a chain of QAbstractProxyIndex

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    edlm
    wrote on last edited by
    #1

    Hi,

    [sorry for my bad english...]

    I try to get the final QModelIndex in a chain of QAbstractProxyIndex (in fact the first in the chain which is a QAbstractItemModel but not a subclass of QAbstractProxyModel).

    This code doesn't work:

    QModelIndex BProxy::mapToSource(const QModelIndex &proxyIndex) const
    {
        QModelIndex index = proxyIndex;
    
        if (index.isValid()) {
            index = QIdentityProxyModel::mapToSource(index);
            QAbstractProxyModel *model = qobject_cast<QAbstractProxyModel *>(sourceModel());
            while (model) {
                index = model->mapToSource(index);
                QAbstractItemModel *sModel = model->sourceModel();
                model = qobject_cast<QAbstractProxyModel *>(sModel);
            }
        }
    
        return index;
    }
    

    The error is QSortFilterProxyModel: index from wrong model passed to mapToSource ASSERT: "!"QSortFilterProxyModel: index from wrong model passed to mapToSource"" in file

    Do you have an idea where is the problem here?

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @edlm said:

      index = QIdentityProxyModel::mapToSource(index);

      mapToSource() is not a static method. You should call it on an instance of your identity proxy model.

      E 1 Reply Last reply
      0
      • Chris KawaC Chris Kawa

        @edlm said:

        index = QIdentityProxyModel::mapToSource(index);

        mapToSource() is not a static method. You should call it on an instance of your identity proxy model.

        E Offline
        E Offline
        edlm
        wrote on last edited by
        #3

        @Chris-Kawa said:

        @edlm said:

        index = QIdentityProxyModel::mapToSource(index);

        mapToSource() is not a static method. You should call it on an instance of your identity proxy model.

        This part doesn't call a static method but the superclass function member (BProxy is a subclass of QIdentityproxyModel).

        Anyway I think I found the problem: in my case I should not override mapToSource because the need to get the QModelIndex of the "final" source model is not systematic. Uniquely when my subclass need it. Otherwise the mapToSource has to work as usual. It was a logical problem and the creation and use of another member function mapToDataSource (with the code above) resolved the bug.

        Thank for your answer.

        1 Reply Last reply
        0
        • Chris KawaC Offline
          Chris KawaC Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @edlm said:

          his part doesn't call a static method but the superclass function member

          Ah yes, sorry. Not my sharpest day I guess ;)
          I'm glad you found a solution.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved