[Qt-interest] question about mixing gui and non gui classess

franki franki at franki.eu.org
Mon May 16 19:56:59 CEST 2011


Hi all,

I have app which communicates with server to display temperature from 
different devices. Question is how to lay out classess which interacts with 
GUI and classess responsible for holding/calculating data. Let's say, I have 
4 pages (widgets of QStackedWidget), each page is separate object (a class) 
that displays data and interact with user, next there are three objects 
(different classess) that are holding data, and exchanging it with different 
QThread that is running network-manager to get/send data from/to server
So far I have such a layout:

MainPages: public QStackedWidget - main class that has GUI pages,
inside this class four other gui classess are created, and pointer for 
managing gui widgets (UI::MainPages ui) is passed to each class, each class 
is responsible for one page of QStackedWidget.
Apart from this, there are three objects that inherits QObject (to be able to 
send signals) also created inside MainPages class, these just share and 
calculate data received from server.
Now, when data arrives from server it first goes to one of three objects, it 
is calculated, and then it goes to one or more "gui" classess to display 
result.

What is worrying me is that all these objects are not related to each other, 
thus all communication between them goes by signal-slot solution. I have more 
than 50 defined connections between these objects and it looks like a mess 
when I look at this.I would like to reorganize it in such a way:

MainPages - creates main Temperature class (pointer for gui objects is passed 
to that class), Temperature class creates "gui" classess as a child objects 
(again pointer for gui is passed), plus classes to calculate data received 
from network-manager are created as children of Temperature class.
Now, lots of data I need to display (after calculation inside Temperature 
class) can be passed to "gui" classess by simple function calls, and I think 
it's simpler and more organized in that way.

The disadvantage of this approach (or at least I think so) is that I need to 
pass pointer to gui elements from MainPages class deep inside classess 
hierarchy, and to the classess that are only  responsible for calculating 
data received from network-manager.

But should that ever worry me? 
What is "blessed" way of laying out objects that are gui related
and these that are only calculating data? And is it safe to pass pointer for 
graphic elements deep inside class hierarchy?

best regards
Marek



More information about the Qt-interest-old mailing list