qt - Passing 2-dimensional QVariantList from C++ to QML -


i confused on how pass 2-dimensional qvariantlist c++ qml, want pass value c++ same assigning in qml this:

property var twodim: [["1-1", "1-2"],["2-1", "2-2"]] 

so can use array model in repeater element doing: modeldata[0] return 1st array of values, , modeldata[1] return 2nd array of values. names , surnames example...

please help

firstly can have qvariantlist of qvariantlists:

// main.cpp int main( int argc, char* argv[] ) {     qguiapplication app( argc, argv );      auto mylist = qvariantlist{};     ( auto = 0; < 2; ++i ) {         mylist << qvariant::fromvalue(                         qvariantlist{ qstring::number( + 1 ) + "-1",                                       qstring::number( + 1 ) + "-2" } );     }      auto view = qquickview{};     view.rootcontext()->setcontextproperty( "mylist", mylist );     view.setsource( qurl{ qstringliteral{ "qrc:/qmlcpptest.qml" } } );     view.show();      return app.exec(); }  // qmlcpptest.qml import qtquick 2.3  item {     property var listoflists: mylist      component.oncompleted: {         ( var = 0; < listoflists.length; ++i ) {             ( var j = 0; j < listoflists[i].length; ++j ) {                 print( i, j, listoflists[i][j] );             }         }     } } 

results in:

qml: 0 0 1-1 qml: 0 1 1-2 qml: 1 0 2-1 qml: 1 1 2-2 

but said in comment, if first dimension represents entity, , second dimension represents properties of entity, superior approach performance , maintenance reasons use qabstractitemmodel (or 1 of it's more specific derived classes).

qt's documentation has lots of stuff on mvc programming, should take time learn subject underpins of qt.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -