Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [solved]Property binding to pointer value
Forum Updated to NodeBB v4.3 + New Features

[solved]Property binding to pointer value

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.1k Views 1 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.
  • W Offline
    W Offline
    winkler3523
    wrote on last edited by
    #1

    Hello,

    i have problems with a property binding. I expose a pointer to a QSortFilterProxyModel through a c++ class to qml, and bind it to a Listview's model property:
    C++:
    @
    class Test {
    Q_OBJECT
    Q_PROPERTY(QSortFilterProxyModel* activeMenu READ activeMenu NOTIFY activeMenuChanged)

    ...

    QSortFilterProxyModel* activeMenu() {
    m_filterModel->setSourceModel(getActiveMenu());
    return m_filterModel;
    }

    ...

    private:
    QSortFilterProxyModel* m_filterModel;
    }
    @
    QML:
    @
    ListView {
    ...
    model: testInstance.activeMenu
    @

    The problem is that the Listview only gets updated the first time. When the sourceModel of the QSortFilterProxyModel changes the Listview's model property stays the same, because it's a pointer to the a QSortFilterProxyModel.

    To get the property binding working on the Listview i changed the c++ class:
    @
    QSortFilterProxyModel* activeMenu() {
    m_filterModel1->setSourceModel(getActiveMenu());
    m_filterModel2->setSourceModel(getActiveMenu());

     m_filterToggle = !m_filterToggle;
     if(m_filterToggle)
       return m_filterModel1;
     else
       return m_filterModel2;
    

    }
    @

    This works as expected, but the solution isn't realy nice.
    Is there a better way to get the property binding working with pointer values?

    Thanks

    1 Reply Last reply
    0
    • W Offline
      W Offline
      winkler3523
      wrote on last edited by
      #2

      Hello,

      i have tested the example again. I observed that the view correctly updates on the change of the sourceComponent from the QSortFilterProxyModel. The problem is that the ListModels onModelChanged signal is not emitted.

      The problem in my application was that i changed the index of the ListView in its onModelChanged handler. In the case of the QSortFilterProxyModel as model, the handler is not called when the sourceModel of the QSortFilterProxyModel changes, and the index was not set correctly.

      Thanks

      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