View Full Version : SIGNAL SLOT performance

3rd April 2009, 13:00

I have a class containing a list of another class objects. Every child objects are connected to a slot in the parent class.

It's a good idea to pass the parent pointer to the childs and let the childrens call directly the method of the parent?
I'm thinking of use this behaviour instead of SIGNALs SLOTs mechanism because it uses a lot of function calls to finally call the method(I'm thinking only on Direct connections).
My application needs to be as faster as can be possible and so I want to increase the performance.


3rd April 2009, 14:22
You can access to the parent widget with method QWidget::parentWidget () .

SIGNAL/SLOT mechanism allow you to have a responsive GUI.
If you call directly parent's method you bypass application event loop and then you have to pay attention to the responsiveness of your GUI.

3rd April 2009, 14:45
If you are inheriting the class, the functions will be available to you, isnt it ?
Why do you need to call them separately ?

And signal/slot arent slow.... are you facing problems with it right now ?

3rd April 2009, 15:57

Thanks, but I never told that the classes are widgets and never told that the child classes are dervied from the first class.

The class A contains a QList<B*>. So class A contains a list of class B object pointers.
When a object B is created and inserted to the list I make some connections that when the object of the class B does something it emits a signal to class A. Is more clear now?

So, is a good idea to pass a parent pointer to the child classes to access direcly to the class A methods or is better to use SIGNAL SLOT mechanism?


3rd April 2009, 16:05
I would use "pass parent pointer to a child", because as was told above, you will use direct calls. but if you don't know anything about parent, i.e. you can't say what kind of objects can be parent then it would be better to implement connection interface between classes using SIGNALS and SLOTS.

3rd April 2009, 17:21

Thanks spirit, it was what I suspect.