qt - can't set custom data for a QStringListModel -
this question has answer here:
i tried set custom data qstringlistmodel
using following code setdata
returns false except when role qt::editrole
:
qstringlistmodel *model = new qstringlistmodel; qstringlist list ; list << "str1" << "str2" << "str3"; model->setstringlist(list); qcombobox *box = new qcombobox; box->setmodel(model); box->show(); qdebug()<<model->index(0); qdebug()<<model->setdata(model->index(0), 1, qt::userrole ); qdebug()<<model->data(model->index(0), qt::userrole ).tostring();
you use standard qstringlistmodel. has no qt::userrole. have implement setdata behaviour qt::userrole yourself. have subclass qstringlistmodel , override setdata() , data().
Comments
Post a Comment