Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I access Qt signals/slots of objects out of scope?

Do the Qt signals/slots follow the scope of native C++?

Let's say I have the following classes: House, Kitchen, Cellar, Stove and Shelf.

class House   {Kitchen kitchen, Cellar cellar;};
class Kitchen {Stove stove;};
class Cellar  {Shelf shelf;};

Now I want to send a signal from the shelf in the cellar to the stove in the kitchen. Is the only way to do this by connecting a signal from the shelf to the cellar and a slot from kitchen to the stove and then in house connecting cellar and kitchen? Or is there a way to do this directly?

I have a class that needs to communicate with a user interface and I wonder if I need to "proxy" all the various signals/slots through intermediate classes. Or is this an indicator of bad design?

like image 871
problemofficer Avatar asked Jan 22 '23 02:01

problemofficer


1 Answers

You can do the connection in any method of House, as there you can access both objects. The "connector" must be able to access both sender and receiver, at compile time, that's all there is to it.

like image 134
Frank Osterfeld Avatar answered Jan 30 '23 07:01

Frank Osterfeld