Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

how to convert c++ modelIndex to QML modelIndex?



  • this is my snip code
    function getIndexFromCpp(tindex)
    {
    var index2,value,value1;
    for(var i=0; i < treeViewModel.rowCount(); i++) {
    value = treeViewModel.data(tindex, treeViewModel.getRoleKey("IdRole"))
    index2 = treeViewModel.index(i,0 );
    value1 = treeViewModel.data(index2, treeViewModel.getRoleKey("IdRole"))
    if(value==value1)
    {
    return i;
    }
    }
    }
    function expandallitem( tindex)
    {
    var i=getIndexFromCpp(tindex);
    var index0 = treeViewModel.index(0,0 )
    var index1 = treeViewModel.index(i,0 )
    expand(index0)
    expand(index1)
    if(index1.has)
    for(var i=0; i < treeViewModel.rowCount(); i++) {
    var index = treeViewModel.index(i,0 )
    sel.select(index,ItemSelectionModel.Select)
    }
    )

    }
    

    it can expand the item with c++ ModelIndex tindex. but select is fail the UI doest has any response..
    getIndexFromCpp: it is my function that convert c++ ModelIndex to QML ModelIndex . anyone has idea?



  • ok i make some mistake and fix the code as below:
    function expandallitem( tindex)
    {
    var parenti= (tindex.parent)
    var parentii= (parenti.parent)
    var i=getIndexFromCpp(tindex);
    var index0 = treeViewModel.index(0,0 )
    var index1 = treeViewModel.index(i,0 )

          expand(parenti)
          expand(tindex )
    
           sel.select(tindex,ItemSelectionModel.Select)
    

    }
    sel is the selection.. and it is still the expand can work well . and slect is fail to work


Log in to reply