PDA

View Full Version : Organizing program structure so that it is easy understandable



Tiansen
29th March 2010, 07:12
Hello,

I am writing a program that is using qtabwidget as a main navigation tool. There is a lot of widgets on each screen and also dialogs that open when user presses some buttons etc.

Now I am facing a problem that I dont know how exactly I should organize code to keep it simple, organized and understandable. Obviuosly code for widgets on all tabs belongs to the same class, because everything what is on different tabs belong to same GUI class. What would you suggest to organize this properly? So that I can divide code for each tabs into maybe different directories or files? I already tried with #include directives but it is very dirty and does not actually work.

wysota
29th March 2010, 09:16
Obviuosly code for widgets on all tabs belongs to the same class, because everything what is on different tabs belong to same GUI class.
That's a bad idea. Each tab should be in each own class. The fact that they belong to the same GUI is meaningless.
Objects should be able to cooperate using a well design API with signals and slots.

Tiansen
29th March 2010, 09:51
That's a bad idea. Each tab should be in each own class.

I agree totally with you. I am just saying that if you use Qt Designer to build GUI, you get only one GUI class for all tabs when using QTabWidget. So there is a way to assign different classes to different tabs?
I think that I must do following then:

1. Make GUI class for each desired tab.
2. Design GUI part of each class (can be done with Designer too).
3. Then assign these GUI classes to each tabs (I think this must be done with code, because Designer doesnt support it).

Am I correct here?

wysota
29th March 2010, 13:41
I agree totally with you. I am just saying that if you use Qt Designer to build GUI, you get only one GUI class for all tabs when using QTabWidget.
No, that only happens if you do everything inside one form.


So there is a way to assign different classes to different tabs?
Yes, at least two such ways. One is to design each tab as a separate widget and then create a QTabWidget in manual written code and add those tabs to the widget there. The other is to make each of your pages a custom widget (either through plugins or by promoting the base class to the custom class) and make a form containing QTabWidget and place those custom widget as pages on the form. The first approach is better because you end up with a simpler hierarchy of objects.