PDA

View Full Version : Can you send a signal from a static callback function?



Eos Pengwern
12th August 2010, 10:36
Hello,

I'm trying to figure out the syntax for how to achieve the following...

From within a member function of a QWidget, I want to invoke a function in an external library which takes a callback as one of its arguments. I want the callback to be something which, when called, sends a signal which can be connected to one of the original QWidget's slots.

The problem is that the callback can't be another member function of the same QWidget, but needs to be a static function of some sort (it could, I think, be a static function belonging to a class, but in most examples I've seen the callback is a stand-alone function not belonging to any class). However, since a static function (even if it belongs to a class) does not belong to an object, I can't see how I would connect a signal from it to my original QWidget's slot.

Is there a way of doing this?

Many thanks,
Stephen.

squidge
12th August 2010, 13:14
If you have a pointer to the class instance, you can connect as usual.

Eos Pengwern
12th August 2010, 13:47
Bingo! Of course you can. I've done precisely that in another application I've written within the past two months.

D-oh!

Thank you very much for the reminder.