Поскольку openNote
является QAction
я могу установить его имя объекта через 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...
В моем автоматическом завершении отображаются все члены, например setData
, objectName
, но не data
. Как я могу получить к нему доступ?
Если я напишу
QAction bla;
bla.data(); //<== auto completion shows "data"
Где моя проблема?
Это решение, которое я выяснил:
void Traymenu::s_showNote(){
QObject* obj = sender();
QAction *noteEntry = qobject_cast<QAction *>( sender() );
int noteID = noteEntry->data().toInt();
qDebug() << "noteID" << noteID;
}