[Qt-interest] class composition & communication in Qt

pmqt71 pmqt71 at gmail.com
Thu Sep 30 17:06:31 CEST 2010


Hi André,

before writing my first post, I was using a dedicate interface (a pure
virtual class) to achieve some decoupling between the parent and the member
class widget.
The MainWindow inherits from the interface (e.g. IPaintingInfo) and
implements the get* methods, the widget use this interface when it needs
info for painting.
This method works well and doesn't allow a complete access to the parent; it
also is faster to write and to execute, but seems not a great design
solution.

pm




2010/9/30 Andre Somers <andre at familiesomers.nl>

> Op 30-9-2010 13:40, Markus Franke schreef:
>
>
> Hi pm,
>
> a signal-slot connection is in most cases the best solution as it provides
> a loose coupling between the parent and the child widget.
>
> You should not use parentWidget() in a child widget (including a
> corresponding cast) and expect to get what you want.
> This would force the child widget always to be used within the same parent
> widget.
>
> I agree, but sometimes, this is what you want. In that case, you should
> however force the type of your parent widget by having the parent argument
> in the constructor for your widget explicitly be of that type (for some
> private subwidget, for instance).
>
> André
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100930/5003ab8b/attachment.html 


More information about the Qt-interest-old mailing list