Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to convert c++ modelIndex to QML modelIndex?
Forum Updated to NodeBB v4.3 + New Features

how to convert c++ modelIndex to QML modelIndex?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 1 Posters 339 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.
  • J Offline
    J Offline
    jimfar
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jimfar
      wrote on last edited by
      #2

      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

      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