Hi, I'm trying to attach a pointer to an QListWidgetItem, to be used in the SLOT itemActivated.
The pointer I'm trying to attach is a QObject* descendant, so, my code is something like this:
Image * im = new Image();
// here I add data to my Image object
// now I create my item
QListWidgetItem * lst1 = new QListWidgetItem(*icon, serie->getSeriesInstanceUID(), m_iconView);
// then I set my instance to a QVariant
QVariant v(QMetaType::QObjectStar, &im)
// now I "attach" the variant to the item.
lst1->setData(Qt::UserRole, v);
//After this, I connect the SIGNAL and SLOT
...
Now my problem, the itemActivated SLOT. Here I need to extract my Image* from the variant, and I don't know how to.
I tried this, but I get the error: ‘qt_metatype_id’ is not a 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();