c++ - Qt: View not updating after QAbstractItemModel::beginInsertRows/endInsertRows -
i have qabstractitemmodel derived model attached qtreeview
i want programatically append single row node somewhere in tree hierarchy.
i have slot connected signal view. signal sends qmodelindex of node want append new row. in slot call begininsertrows(...) using qmodelindex , the new row's row number, append new row model data, , call endinsertrows():
the value passed begininsertrows(...) number of child rows parent node has prior appending new node.
that is, if there 4 child rows, have row indices 0, 1, 2 , 3. therefore new row number added 4.
void model::slotonaddrow(qmodelindex parent, std::string key) { assert(parent.isvalid()); row& parent_row = *static_cast<row*>(parent.internalpointer()); begininsertrows(parent, parent_row.numchildren(), parent_row.numchildren()); parent_row.addchildrow(key); endinsertrows(); } the problem i'm having after calling endinsertrows() view not update.
example:
here example of tree view.
scenario:
- i want append new row
spread_1. spread_1has 4 children rows:- 0:
inst_id - 1:
leg_1 - 2:
leg_2 - 3:
leg_3
- 0:
- the new row therefore have row index 4, call
begininsertrows(spread_1, 4, 4);
i this, , my view not show new row.
proof node exist:
i know row exists in model, because if collapse spread_1 node, , re-expand it, newly added row visible:
question:
afaikt i've followed example online correctly, i'm missing something.
how can append new row tree node, , have view update?
do need emit signal or override base class method?
an issue indicative of error elsewhere in model. without seeing implementation of model impossible where.
using model test can helpful in diagnosing issue.
literally need instantiate modeltest instance model
qtreeview(&_model); modeltest test(&_model); if model doesn't conform, assertion failures modeltest


Comments
Post a Comment