Qt5 C++ connect triggered QAction to a member function
c++, qt5
Solution
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`.
Problem
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)` ``` ^ ```