We can define static slots .
Code:
auto action = menu->addAction("edit"); return menu; } Q_SLOT static void onClicked(){ throw; }
Just I wonder that how to get whos the sender ? Is there a direct way to get it ?
Printable View
We can define static slots .
Code:
auto action = menu->addAction("edit"); return menu; } Q_SLOT static void onClicked(){ throw; }
Just I wonder that how to get whos the sender ? Is there a direct way to get it ?
Hello,
In your slot:-You should be able to manipulate senderObj, I don't know if this works in static slots.
Regards
Almost certainly not. QObject::sender() is a protected, non-static method of the QObject class, so the only way you can call it is from within a member function of a class derived from QObject. The only way to call a non-static member function is through an instance of the class, and since a static method in most cases is called without an instance, there is no way to call sender().Quote:
I don't know if this works in static slots.
I don't think so. In this case, the slot is nothing more than an ordinary function so there is no way in C++ that I know of to determine who is calling the function when you are inside it.Quote:
Just I wonder that how to get whos the sender ? Is there a direct way to get it ?
I'd say that it doesn't make that much sense to have a static slot like that. You can instead use a lambda expression as a slot where the sender can be accessed directly.
Interesting. Are lambda expressions treated as if they were inline member functions of the class in which they are declared? Or are you suggesting that the pointer to the sender be given as one of the scope arguments to the lambda?Quote:
You can instead use a lambda expression as a slot where the sender can be accessed directly.
Yes, you need to pull in the relevant object into the closure.