PDA

View Full Version : Signals and Slots querry -- urgent



LiCodeX
2nd August 2007, 08:28
I've a question, although I know that, only member functions are used for implementing Singnals and Slots using connect(), is there any way to call /use a non-member function which has been already declared and defined in other file, related to the same application, as a SLOT using connect() ??

Any help will appreciated in this regard.

Thanks

marcel
2nd August 2007, 08:42
No. Signals/slots only work with classes that have the Q_OBJECT macro.
The moc won't know hot to compile that code if you use an application static function.
Why don't you make a wrapper for that function in a class? You know, create a method that calls the global function.

Regards

LiCodeX
2nd August 2007, 10:41
No. Signals/slots only work with classes that have the Q_OBJECT macro.
The moc won't know hot to compile that code if you use an application static function.
Why don't you make a wrapper for that function in a class? You know, create a method that calls the global function.

Regards

yeah I thought of that, but wanted to clear it with someone who knows Qt pretty well. And your suggestion for writting a wrapper is very valid point and I was actually going to do the same, if there wouldn't have been any other way for calling a non-member static function through Signals/Slot mechanism.
It will be helpful if somebody do come up with something like that wrapper function, which calls a static function, when Signals and Slots are connected.

I suppose I may get back to it soon.

Thanks :)

marcel
2nd August 2007, 10:45
It will be helpful if somebody do come up with something like that wrapper function, which calls a static function, when Signals and Slots are connected.

I don't know about that.
I suppose one could make this more general using pointers to functions (or even lambda functions if they ever become available).

But this is basically a simple process of just calling one function and everybody just adds wrappers. It is just like calling a function from an external non-Qt library as response to a signal.

Regards