Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-67294

QSortFilterProxyModel from C++ unavailable in QML unless we import QtQuick.Controls

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • P2: Important
    • None
    • 5.6.3, 5.9.4
    • None

    Description

      If we expose a QSortFilterProxyModel derived class to the QML engine it doesn't work and fails with:

      Unable to assign MyModel to [unknown property type]

      This is on the line where I try to set the sourceModel property in QML. It starts working as soon as I:

      import QtQuick.Controls 1.5

       Interesting enough it's complaining about a property of a QAbstractItemModel* type, while a QAbstractItemModel derived class, used in a view works flawlessly even without importing QtQuick.Controls. Is that by design or a bug? I didn't find the documentation which states that QtQuick.Controls are needed in order to get QSortFilterProxyModel to work in QML.

       

      my class has a basic signature of:

       

      class BCSortFilterProxyModel : public QSortFilterProxyModel
      {

          Q_OBJECT

      public:
          BCSortFilterProxyModel(QObject * parent = 0);
          ~BCSortFilterProxyModel();
          Q_INVOKABLE    void    setSourceModel(QAbstractItemModel * sourceModel);
          Q_INVOKABLE void    setMultiFilter(const QVariantMap &filter);

          Q_PROPERTY(QAbstractItemModel* sourceModel READ sourceModel WRITE setSourceModel)
          Q_PROPERTY(QVariantMap multiFilter READ multiFilter WRITE setMultiFilter)
          
          QVariantMap multiFilter() const;
          QAbstractItemModel* sourceModel() const {return dataModel;}
          
          
      protected:
          bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const;

      private:

          BCItemModel                *dataModel;

          QMultiMap<int, QString>    mFilter;

      }

       .. registered to QML with ...

      qmlRegisterType<BCSortFilterProxyModel>("BecozLib", 1, 0, "BCSortFilterProxyModel");

       

      and used like:

      import BecozLib 1.0

      BCSortFilterProxyModel {
          id: filteredModel
          sourceModel: MyModel
          multiFilter: {"myRole": ">=100", "myRole": "<200", "mySecondRole": "=true"}
      }

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            shausman Simon Hausmann
            buldozer Toni Rutar Lokar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes