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. Qml listview add new row to a sub vector in the model
Forum Updated to NodeBB v4.3 + New Features

Qml listview add new row to a sub vector in the model

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 432 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.
  • S Offline
    S Offline
    stephens
    wrote on 21 May 2019, 10:57 last edited by
    #1

    I have got a custom structure defined in C++, which contains several variables among them is a QList variable. I can now add a new structure dynamically in Qml listview, but my question is I also want to add a new item into QList inside the structure, I can do this in the background but fail to update the listview.

    I think the error appears in the connect() function in C++. As I understand in order to add a new row need to call beginInsertRows() and endInsertRows(), but should be sender and receiver be the same in these two scenarios?

    connect(mList, &PropertyList::preItemAppended, this, = {
    const int index = mList->items().size();
    beginInsertRows(QModelIndex(), index, index);
    });
    connect(mList, &PropertyList::postItemAppended, this, = {
    endInsertRows();
    });

    connect(mList, &PropertyList::preParamAppended, this, [=]() {
        const int index = mList->getParams().size();
        beginInsertRows(QModelIndex(), 0, 0);
    });
    connect(mList, &PropertyList::postParamAppended, this, [=]() {
        endInsertRows();
    });
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 May 2019, 21:19 last edited by
      #2

      Hi,

      It looks a bit convoluted. The usual implementation is rather:

      beginInsertRows(modelIndex, start, end);
      // do what needs to be done
      mList.append(item);
      endInsertRows();
      

      In the method where you trigger adding a new row.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      1/2

      21 May 2019, 10:57

      • Login

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