为什么我无法连接动作以在触发时调用该函数? 我认为我已根据此source理解语法 可以直接调用函数。
void Traymenu::createMainContextMenu(){
QAction *actionNewNote = mainContextMenu.addAction("Test Func");
QObject::connect(actionNewNote,QAction::triggered,Traymenu::testFunc);
mainIcon.setContextMenu(&mainContextMenu);
}
void Traymenu::testFunc(){
printf("test func");
}
错误:invalid use of non-static member function 'void QAction::triggered(bool)
^
答案 0 :(得分:5)
您需要将函数指针传递给connect
。您还需要传入指向接收对象的指针:
QObject::connect(actionNewNote, &QAction::triggered, this, &Traymenu::testFunc);
请注意&
之前的“QAction::triggered
”。