C++11-signal-slot-syntax, use member function "pointers" as function arguments
Greetings, everyone!
I've got a class that represents kind of a tool bar. To add an action, I've managed to provide the following two methods:
These methods allow me to do things like these:
Code:
theToolBar->addAction("foo", theReceiver, SLOT(theSlot()));
theToolBar->addAction("bar", [](){ bar(); })
Now one thing I did not accomplish: Use the new cool C++11-signal-slot-syntax!
I'd like to write my code like this:
Code:
theToolBar->addAction("foobar", theReceiver, &TheReceiverClass::theSlot)
But how would the signature of the new overload of addAction look like?
I would appreciate any help. (Quite honestly, this wouldn't be an important fetaure at all but at least it would be consistent.)
Maximilian
Re: C++11-signal-slot-syntax, use member function "pointers" as function arguments
Given that the method signature is e.g.,
then the type is,
Code:
void (TheReceiverClass::*)(int)
I suggest you typedef this like,
Code:
void (TheReceiverClass::*MyTypeDef)(int);
making your addAction look like,
Code:
addAction
(string,
QObject*, MyTypeDef
);
Re: C++11-signal-slot-syntax, use member function "pointers" as function arguments
It's a Qt5 syntax, not a C++11 one. The only thing C++11 introduces in this regard is lambda expressions.