What is the correct Qt idiom for exposing signals/slots of contained widgets?

Posted by Tyler McHenry on Stack Overflow See other posts from Stack Overflow or by Tyler McHenry
Published on 2010-04-01T00:17:25Z Indexed on 2010/04/01 0:23 UTC
Read the original article Hit count: 672

Filed under:
|
|

Suppose I have a MyWidget which contains a MySubWidget, e.g. a custom widget that contains a text field or something. I want other classes to be able to connect to signals and slots exposed by the contained MySubWidget instance. Is the conventional way to do this:

  1. Expose a pointer to the MySubWidget instance through a subWidget() method in MyWidget
  2. Duplicate the signals and slots of MySubWidget in the MyWidget class and write "forwarding" code
  3. Something else?

Choice 1 seems like the least code, but it also sort of breaks encapsulation, since now other classes know what the contained widgets of MyWidget are and might become dependent on their functionality.

Choice 2 seems like it keeps encapsulation, but it's a lot of seemingly redundant and potentially convoluted code that kind of messes up the elegance of the whole signals and slots system.

What is normally done in this situation?

© Stack Overflow or respective owner

Related posts about c++

Related posts about qt