Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

how to get lists dynamically from c++

$
0
0
Hello folk, i have a set of listmodels in c++ that i am trying to view in QML. suppose i have 2 groups and each group contains a certain number of folders. i have written a few function that create seperate lists for each level of items. So now i have 1 list that contains all the groups and 2 lists that contain the folders of the groups list 1 = groups (2 groups in this case) list 2 = folders of group 1 list 3 = folders of group 2 Group1 (list1)   Folder1 (list2)   Folder2 (list2) Group2 (list1)   Folder1 (list2)     <-- (in this case both folder lists contain the same items)   Folder2 (list2) The following code creates a nested list of list 1 and list 2 Rectangle {     height: 300     width: 300       Component {         id: folderDelegate         Item {             width: 100             height: col2.childrenRect.height               Column {                 id: col2                 anchors.left: parent.left                 anchors.right: parent.right                   Text {                     id: name1                     text: " " + model.Name                 }             }         }     }       ListView {         id: outer         model: myModel         delegate: groupsDelegate         anchors.fill: parent     }       Component {         id: groupsDelegate           Item {             width: 100             height: col.childrenRect.height               Column {                 id: col                 anchors.left: parent.left                 anchors.right: parent.right                   Text {                     id: t1                     text: model.Name                 }                   ListView {                     id: folderlist                     model: foldermodel                     delegate: folderDelegate                     contentHeight: contentItem.childrenRect.height                     height: childrenRect.height                     anchors.left: parent.left                     anchors.right: parent.right                     clip: true                 }             }         }     } } what i am trying to do is to add list 3 beneath the 2nd item of the group list so this: Group1 (list1)   Folder1 (list2)   Folder2 (list2) Group2 (list1)   Folder1 (list3)     <-- (the folders of group2 should be displayed here)   Folder2 (list3) so my question is, how can i add the list dynamically? i was thinking of writing a function in c++ that gives QML the name of the listmodel through a QString. But doing something like ListView {    model: object.getStr()  <<---(function that returns the name of a model with a QString } function: Q_INVOKABLE QString getStr( return name ); but this does not work. how could i get something like that to work? after this, i would also need to be able to click on a folder to make a new screen appear that holds a list of all the items in the folder. I think that if i can make this work, expanding it to different levels of detail should work aswell Thanks in advance!!

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images