Can I "connect" using QAction as sender ?
-
EDIT
I got the answer herehttps://forum.qt.io/topic/131708/multiple-qaction-and-using-sender-to-get-which-got-selected/2
Very basic question, and if the answer is no , can you suggest alternative to "connect" using QAction ?
The attached TEST C++ code works with sender QMenu and gets me ton of error messages when the sender is QAction,
connect(subMenu[index_sub] , &QMenu::triggered, this , [=]() { this->processAction(index_sub,index) ;}); // connect to main submenu connect(TEMP_[index] , &QMenu::triggered, this ,[=]() { this->processAction(index_sub,index) ;}); -
EDIT
I got the answer herehttps://forum.qt.io/topic/131708/multiple-qaction-and-using-sender-to-get-which-got-selected/2
Very basic question, and if the answer is no , can you suggest alternative to "connect" using QAction ?
The attached TEST C++ code works with sender QMenu and gets me ton of error messages when the sender is QAction,
connect(subMenu[index_sub] , &QMenu::triggered, this , [=]() { this->processAction(index_sub,index) ;}); // connect to main submenu connect(TEMP_[index] , &QMenu::triggered, this ,[=]() { this->processAction(index_sub,index) ;});@AnneRanch
If the signal is not there in
QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...@AnneRanch said in Can I "connect" using QAction as sender ?:
connect(TEMP_[index] , &QMenu::triggered,
And if
TEMP_[index]is aQAction, you need to change it to&QAction::triggered -
@AnneRanch
If the signal is not there in
QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...@AnneRanch said in Can I "connect" using QAction as sender ?:
connect(TEMP_[index] , &QMenu::triggered,
And if
TEMP_[index]is aQAction, you need to change it to&QAction::triggered@Pl45m4 Thanks, just found my error.
-
@AnneRanch
If the signal is not there in
QAction, how would you be able to use it?! Of course it does't work, if you use random signals and try to use them with other classes...@AnneRanch said in Can I "connect" using QAction as sender ?:
connect(TEMP_[index] , &QMenu::triggered,
And if
TEMP_[index]is aQAction, you need to change it to&QAction::triggered@AnneRanch
@Chris-Kawa explained here, how actions are added to a menu.
If I remember your code correctly from previous posts,
TEMP_is an array ofQMenu.
So the connect statement connects to a menu, which works only with signals ofQMenuor one of its base classes.QActionisn't such a base class ofQMenu, which is the reason for your compiler errors.It's not possible to suggest a working alternative, because we don't know where you store the pointer to the
QActionreturned byaddAction("yourText").
Let's assume it is stored inQAction *tempAction.
In that case the following would work:connect(tempAction, &QAction::triggered, this, [=]() {this->processAction(index_sub, index); });