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 objectModel
Forum Updated to NodeBB v4.3 + New Features

QML objectModel

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 1 Posters 471 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by
    #1

    Hi,
    i'm trying to create objects list (qml side) with values that i read in file with c++ methode.

    when on_PropValsChanged is emited i have to create object with the properties inside _propVals variant, and i need to keep the objects somewhere i can access it whenever i need

    So i tryed to put my objects in a ObjectModel as described here
    http://doc.qt.io/qt-5/qml-qtqml-models-objectmodel.html
    and show them in ListView

    but as soon i click on my ListView (to scroll) my app crashes

    calling objectMod.get(some index)._name will also result to a crash

    The process was ended forcefully.

    // object creation

     on_PropValsChanged: {
         
            var tmp = _propVals
            var comp = Qt.createComponent("Obj.qml")
            var obj = comp.createObject(cont)
     
            obj._vId=tmp[0]
            obj._name=tmp[1]
            obj._alias = tmp[2]
            obj._slaveId= tmp[3]
            obj._storageType =tmp[4]
            obj._dataType =tmp[5]
            obj._bitSz= tmp[6]
            obj._bitOffset =tmp[7]
            obj._slaveFixAdress = tmp[8]
            obj._type = tmp[9]
            obj._direction = tmp[10]
            obj._index = tmp[11]
            obj._motionType = tmp[12]
            obj._motionDirection = tmp[13]
            obj._motionIndex = tmp[14]
    
            objectMod.append(obj)
       
        }
      ObjectModel {
            id: objectMod
            onChildrenChanged: console.log(children) // the objects are added with the prop values correctly
    
        }
    

    //Obj.qml

    Rectangle {
        property string _vId : ""
        property string _name : ""
        property string _alias : ""
        property string _slaveId : ""
        property string _storageType : ""
        property string _dataType : ""
        property string _bitSz : ""
        property string _bitOffset : ""
        property string _slaveFixAdress : ""
        property string _type : ""
        property string _direction : ""
        property string _index : ""
        property string _motionType : ""
        property string _motionDirection : ""
        property string _motionIndex : ""
    
    
        ColumnLayout{
            anchors.fill: parent
    
            RowLayout{
                Text{
                    text : "variable id :"
                }
                Text{
                    text : _vId
                }
            }
    }
    

    If someone has a better approche please tell me how should i do.
    qt5.11 mingw32

    1 Reply Last reply
    0
    • ODБOïO Offline
      ODБOïO Offline
      ODБOï
      wrote on last edited by
      #2

      finnaly i used qobjectlist-based-model
      http://doc.qt.io/qt-5/qtquick-modelviewsdata-cppmodels.html#qobjectlist-based-model

      1 Reply Last reply
      1

      • Login

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