0

I have a doubt with canFetch() and fetchMore() functions. i am implementing tree structure, when i scroll till the end canfetch() will be call and if returns true fetchMore() will be called where we have to fetch the data and insert items into tree.

void model::fetchMore(const QModelIndex& f_parent)
{
    //fetch the data needed and create items
    beginInsertRows(f_parent, row, lastRow);
    endInsertRows();
}

Please let me know In beginInsertRows, what numbers exactly we need to specify, It is confusing me..

I have fetched some data now, in that from top I have 5 child's and followed by 10 parents and each parent has 10 child's. (f_parent parent has 5 childs already)

Now I need to insert 5 more children followed by 10 parents.

now what numbers I need to specify in beginInsertRows() exactly.

  • beginInsertRows(f_parent,5,f_parent.row()+10); ?
  • beginInsertRows(f_parent,f_parent.row(),f_parent.row()+10); ?
  • beginInsertRows(f_parent,5,10); ?
NDestiny
  • 1,133
  • 1
  • 12
  • 28
  • have you checked the documentation? seems pretty clear and has a diagram to explain the params required http://doc.qt.io/qt-5/qabstractitemmodel.html – AngryDuck Apr 23 '15 at 16:29
  • @AngryDuck Documentation describes every thing in terms of list, not in terms of tree.. And i have gone through the documentation already and googled also. – NDestiny Apr 23 '15 at 17:30
  • This example has some more information: http://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html. Basically, Every parent, starting from the invisible root index, is a a parent of a 2D table. Each cell in this table can also be a parent of another 2D table, and so on. – oranja Mar 02 '17 at 09:58
  • And to answer your question: You will need to call `beginInsertRows` multiple times. Once for each parent and once for each batch of children. – oranja Mar 02 '17 at 10:01

0 Answers0