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] Dynamically add element to a model (using javascript) made with C++ backend
Forum Update on Monday, May 27th 2025

[SOLVED] Dynamically add element to a model (using javascript) made with C++ backend

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.8k Views
  • 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.
  • A Offline
    A Offline
    AlterX
    wrote on 19 May 2012, 17:57 last edited by
    #1

    Hi all,
    I'm finding a way to add/remove item from a ListView;
    In my C++ file, I've created a model using QList<QObject *> and setContextProperty(); all went ok and it works.
    My problem now is to add/remove new element from within javascript...I was hoping that a simple

    @myListObject.model.append({"nickname":nickname});@

    was enought, but... a beautiful:
    myListObject.model.append' [undefined] is not a function.

    was shown to me even myListObject and model are both valid!!
    I've thought that happen because QList<QObject*> doesn't create a real ListModel (with all function like append, insert and so on...)
    Is there someone that know how to resolve this?!?

    Thank you
    Gianni

    Qt Ambassador
    Real-time cooperative teams: http://www.softairrealfight.net
    Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

    https://codereview.qt-project.org/...

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AlterX
      wrote on 4 Jun 2012, 10:06 last edited by
      #2

      For those who can be interested in that, I've resolved, but not in a elegant way!
      In myListView I've created a qml ListModel attached to ListView and then thru javascript functions they manipulate ListModel.
      But important, you cannot pass from within C++ to qml a flat QList<QObject*> because itsn't supported well, instead you need to pass the QList thru setContextProperty of QDecalarativeContext to use in qml

      Bye

      Qt Ambassador
      Real-time cooperative teams: http://www.softairrealfight.net
      Free Real-time network platform sdk: https://github.com/AlterX76/Solomon

      https://codereview.qt-project.org/...

      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