小编Leo*_*amé的帖子

QVariant到QObject*

我正在尝试将指针附加到一个QListWidgetItem,用于插槽itemActivated.

我试图附加的指针是一个QObject*后代,所以,我的代码是这样的:

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
...
Run Code Online (Sandbox Code Playgroud)

现在我的问题,itemActivated插槽.在这里,我需要Image*从变体中提取我,我不知道如何.

我试过这个,但是我得到了错误:

'qt_metatype_id'不是'QMetaTypeId'的成员

void MainWindow::itemActivated( QListWidgetItem * …
Run Code Online (Sandbox Code Playgroud)

c++ qt4

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

c++ ×1

qt4 ×1