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. QAbstractListModel: connect item's signal to the dataChanged signal of the model
Forum Updated to NodeBB v4.3 + New Features

QAbstractListModel: connect item's signal to the dataChanged signal of the model

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.3k 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.
  • E Offline
    E Offline
    Etchelon
    wrote on last edited by
    #1

    Hi,

    I have subclassed QAbstractListModel for exposing a list of my objects to QML (using a ListView, there).
    I know that I can change the properties of items by overriding setData in my class, but that works from QML when I assign something to the corresponding role:
    @void setData(QModelIndex index, QVariant value, Role role)
    {
    switch (role)
    {
    case NameRole:
    m_list[index.row()]->set_name(value.toString());
    emit dataChanged(index, index, { NameRole });
    break;
    }
    }
    @
    and from QML, in the delegate of the ListView:
    @Item {
    Button { onClicked: name = "randomString"; }
    }@

    Now, I want to open a popup with a few controls that will let me choose a value for one of the properties, and a button for confirmation. I tried passing to the popup a pointer to the element (say, I got a MyClassModel, and the popup stores a @property MyClass item@), but invoking the setter, for that property, directly on the element doesn't trigger the dataChanged event on the model, and the view remains unaltered.

    For now I have added a function to my model:
    @void set_property(int i, QString name, QVariant value)@
    where I manually set the property called name of the item with index i and then emit dataChaged; however, I was wondering if there's a better solution from QML, something that allows me to write inside the popup, which is a separate QML item (file), myproperty = newValue and have the system automatically call the underlying model's setData function; or, maybe in the model's append function, from C++, I can manually connect each of the items' propertyChanged signal to a slot in the model which will in turn emit dataChanged signal for the corresponding row...

    I think, and I certainly hope, I've been clear enough and that someone will help :)

    1 Reply Last reply
    0
    • E Offline
      E Offline
      Etchelon
      wrote on last edited by
      #2

      Up please

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nickaein
        wrote on last edited by
        #3

        I guess this is a common case. Any answers for this question?

        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