未找到QAction“数据”成员

时间:2014-02-23 21:47:08

标签: c++

由于openNoteQAction我可以通过setObjectName设置其对象名称。那为什么我不能访问数据呢?我不知道。

QAction *openNote; 
QVariant noteID;    
openNote = m_mainContextMenu.addAction(menuEntryName);
openNote->setObjectName("noteEntry");     //QAction::setObjectName

int ID = m_noteList[0].data()->getID();
noteID.setValue(ID);
openNote->setData(noteID);                //QAction::setData

connect(openNote,SIGNAL(triggered()),this,SLOT(s_showNote()));

我的插槽:

void Traymenu::s_showNote(){
    QObject* obj = sender(); //sender is "openNote" of type QAction
    qDebug() << "objectName" << obj->objectName();  //works, because obj = QAction
    obj->data();      //no member data found?! Why? Documentation says there is...

我的自动完成功能会显示每个成员,例如setDataobjectName,但不是data。我怎样才能访问它?

如果我写

QAction bla;
bla.data(); //<== auto completion shows "data"

我的问题在哪里?

1 个答案:

答案 0 :(得分:0)

这是我发现的解决方案:

void Traymenu::s_showNote(){
    QObject* obj = sender();
    QAction *noteEntry = qobject_cast<QAction *>( sender() );
    int noteID = noteEntry->data().toInt();
    qDebug() << "noteID" << noteID;
}
相关问题