c++ - QVariant to QObject* -


i'm trying attach pointer qlistwidgetitem, used in slot itemactivated.

the pointer i'm trying attach qobject* descendant, so, code this:

image * im = new image();   // here add data image object // create item qlistwidgetitem * lst1 = new qlistwidgetitem(*icon, serie->getseriesinstanceuid(),  m_iconview); // set instance qvariant qvariant v(qmetatype::qobjectstar, &im) // "attach" variant item. lst1->setdata(qt::userrole, v); //after this, connect signal , slot ... 

now problem, itemactivated slot. here need extract image* variant, , don't know how to.

i tried this, error:

‘qt_metatype_id’ not member of ‘qmetatypeid’

void mainwindow::itemactivated( qlistwidgetitem * item ) {     image * im = item->data(qt::userrole).value<image *>();     qdebug( im->getimage().toascii() ); } 

any hint?

image * im = item->data(qt::userrole).value<image *>(); 

the answer this

// qvariant qobject * qobject * obj = qvariant_cast<qobject *>(item->data(qt::userrole)); // qobject* myclass* myclass * lmyclass = qobject_cast<myclass *>(obj); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -