Estoy tratando de conectar un puntero a un QListWidgetItem
, para ser utilizado en la ranura itemActivated
.QVariant to QObject *
El puntero Estoy intentando conectar es un descendiente QObject*
, así, mi código es algo como esto:
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
...
Ahora mi problema, la ranura itemActivated
. Aquí necesito extraer mi Image*
de la variante, y no sé cómo hacerlo.
yo probamos este, pero me sale el 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());
}
Cualquier pista?
Image * im = item->data(Qt::UserRole).value<Image *>();
Desde el 'QVariant (int TypeId, const void * copia)' documentación Héctor: "Por lo general, nunca se tiene que utilizar este constructor, utilice [QVariant :: fromValue()] (http://doc.qt.io/qt-5/qvariant.html#fromValue) para construir variantes de los tipos de puntero representados por QMetaType :: VoidStar y QMetaType :: QObjectStar " –
También tenga en cuenta que el tipo de '& im' es' Imagen ** ', no' Imagen * '. –