c++ - QT - How to retrieve QVariant Values from combobox? -
i'm using qvariant store object inside of qcombobox, appears work fine. implementing code:
add type qvariant in header:
q_declare_metatype(cdiscrecorder*) pdiscrecorder casted cdiscrecorder:
cdiscrecorder* pdiscrecorder = new cdiscrecorder(); then stored in combobox
ui->cbdrives->additem(qstring::fromwchararray(strname), qvariant::fromvalue(pdiscrecorder)); the problem arises when try pull out:
cdiscrecorder* discrecorder = this->ui->cbdrives->itemdata(index).value<cdiscrecorder*>; i receive error:
error c3867: 'qvariant::value': function call missing argument list; use '&qvariant::value' create pointer member i tried implement hint in error code no avail, have followed thread add qobject in combo box of qt implement behavior, how can object ?
thanks
the compiler giving hint argument list missing - should need add brackets tell you're trying call function. change
cdiscrecorder* discrecorder = this->ui->cbdrives->itemdata(index).value<cdiscrecorder*>(); and should work. that's quite long line, might cleaner break out
qvariant variant = this->ui->cbdrives->itemdata(index); cdiscrecorder* discrecorder = variant.value<cdiscrecorder*>();
Comments
Post a Comment