c++ - Search QTableView with a value(e.g. ID) which is not displayed -
scenario:
say, have person class
class person{ int id; // unique value, not displayed qstring name; // displayed qstring address; // displayed qstring age; // displayed etc etc // displayed }
the model class using; inherits qabstracttablemodel - mycustommodelclass : qabstracttablemodel
. mycustommodelclass
has reference person list. person list maintained in class called myalldata
outside of model class.
the table does not display id number of person. thing 1 can identify person separately. if want search table data id how can that?
it depends bit on method search model class with. usually, implement qt::userrole in data() method. role either return id or pointer complete structure (using q_declare_metatype).
then, can either work way through model indices on own, calling
model->data(idx, qt::userrole).tovalue<person*>()
or use methods qt's match(.) , use qt::userrole there.
a third possibility return id if display it, hiding column in view.
Comments
Post a Comment