Reputation: 4700
Why can't I connect the action to call the function if triggered? I thought that I've understood the syntax according to this source that states one can call a function directly.
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");
}
Error:invalid use of non-static member function 'void QAction::triggered(bool)
^
Upvotes: 3
Views: 2035
Reputation: 7777
You need to pass pointers to functions into connect
. You also need to pass in a pointer to the receiving object:
QObject::connect(actionNewNote, &QAction::triggered, this, &Traymenu::testFunc);
Note the "&
" prior to QAction::triggered
.
Upvotes: 6