[Qt-interest] A design problem
hugh
hdixon at bigpond.net.au
Mon May 3 00:58:06 CEST 2010
On Mon, 3 May 2010 05:27:30 am lists4pghanghas wrote:
> Hi
>
> I am having some design problems with my qt development. not to mention
> I am new to Qt and OOP development. Here is one of them:
> When I do implement subclasses for my particular use. I find it hard to
> decide where to handle qt keypress events. Say I have a small gui
> component that will need some drawable elements as its children and
> sometimes the parent child hierarchy can go deeper. Now I am faced with
> the task of choosing where to handle the key events, All in the ultimate
> parent or with every element(leaving unhandled key event for its parent)
> thus making them focusable (as a prerequisite) and everybody signals
> there change in state or anything due to keys by emitting a signal, and
> then that signal can be propagated upwards if required. But the second
> approach sometime leads to chaining of signals if only the ultimate
> parent is exposed to the rest of the application. eg child's signal
> connected to its parents slot or signal, then parents signal connected
> to its parents signal or slot ultimately reaching a stage where its
> available to rest of the application as a whole.
>
> Thanks
> PSG
>
Hi PSG,
I spent many years doing OO development under Windows, and this was always a
problem to me. In the end I decided that sometimes it is better to handle the
signal at the top level widget, but at other times to handle it at the specific
widget/control.
When you talk about the parent and child widgets, I hope you are talking about
widgets within other widget on the dialog/panel/top level widget. This is not
a matter for C++ inheritance! I found it best to keep the number of widgets
within widgets small, that is what I would call a flat structure. This reduces
the number of "generations" of parent/child in your layout.
Whichever way you do this you will need to either pass the signals up, or down
the structure. Encapsulation is an OO concept where, in this case you try to
reduce how many other widgets need to be signalled when a particular event
happens.
I had a number of widgets that were used in many places, and for these it was
easier to have them do the processing, as it made placing them in new layouts
easier.
I hope I have not confused you.
I guess the important thing is are you sure you need so deep a structure,
because that is why you have the long chains of signal/slots.
H
More information about the Qt-interest-old
mailing list