[Qt-interest] Signal-slot routing in a complex GUI

Srdjan Todorovic todorovic.s at googlemail.com
Mon May 10 15:18:07 CEST 2010


Hi,

On 10 May 2010 14:01, Pavel Zdenek <pavel.zdenek at gmail.com> wrote:

> application. The QMainWindow dependence tree has two or more fairly
> long branches, where the signal source is down in one and the target
> slot is in another. Let's say an QMdiArea with a QDockWidget. One
> branch is QDockWidget>QVBoxLayout>list of custom QWidgets>row of
> QCheckBoxes. Another branch is a
> QMdiSubWindow>QTabWidget>QGridLayout>QButton. I want to disable some
> checkboxes with a button click(). How would you do that?
>
> For me, it always resulted in tons of boilerplate signals and slots
> everywhere, which single purpose is to route the event up and down.
> It's hard to manage because of the myriad of connect() calls
> everywhere, and on the way it pollutes the container classes which do
> not care at all. Connecting signals to signals helps a little bit, but
> you just reduce the mess, not solving it.

Do you know in advance which checkboxes will be controlled by which pushbuttons?

This might not be a very elegant way to do it, but how about (ascii pseudo-UML):

[checkboxes]---<>[ControlMapper]<#>-----[pushbutton]

You create a ControlMapper and store it somewhere in a collection
where you can easily get to it.
Have your button attach itself to the mapper as the controller, and
have your pushbuttons attach themselves as the slaves.

I did something similar in a small app I wrote a few months ago where
I wanted to map 2 network connections and a MDI window together. But I
did it so that all the connects were inside the mapper class so that I
didn't have to mess about with too many connect() disconnect() calls.

Don't know if that helps you...

Regards,
Srdjan



More information about the Qt-interest-old mailing list