PDA

View Full Version : help setting up qt4 ui from qt3



illuzioner
23rd June 2007, 04:42
hi,

i spent a load of time in qt3 building a ui file and then sublcassing the resulting generated files to be my main window. the procedure in qt4, however, is throwing me off.

for example, i created test.ui, which (when compiled) generated test.h and test.cpp. i also added functions into test.ui.h, and the class name is called testClass (which is a QMainWindow sublcass).

since i needed more functionality in the class, i subclassed testClass as testSubClass into files testSubClass.cpp and testSubClass.h. in main.cpp, i create an instance of testSubClass which acts as my main window.

so far i have for qt3:
files i created
---------------
test.ui test.ui.h
testSubClass.cpp
testSubClass.h

generated files
---------------------
test.cpp, test.h

and i define my testSubClass as

class testSubClass : public testClass

i'm now trying to translate this into qt4's new and confusing ui structure.

so far i have for qt4:
files i created
---------------
test.ui
testSubClass.cpp <--- leftover from qt3 architecture. contains all the functionality
testSubClass.h

generated files
---------------------
ui_test.h

how do i define testSubClass now? is it a testClass subclass or a QMainWindow subclass or both?

where does this new ui.setupUi() go, in main or in testSubClass.cpp in the testSubClass constructor?

when do i use this Ui namespace??

i've read the sparse documentation on making these changes and that's what got me this far, but i'm lost in getting past this.

thanks!! -- lou

marcel
23rd June 2007, 07:25
You can choose between either the single inheritance approach or the multiple inheritance approach. You can read about both of them in the documentation.

Single inheritance:


how do i define testSubClass now? is it a testClass subclass or a QMainWindow (http://doc.trolltech.com/latest/qmainwindow.html) subclass or both?

For this case is a subclass of QMainWindow and contains a member of type Ui::testClass( this is the one generated by uic ).


when do i use this Ui namespace??

Right there...


where does this new ui.setupUi() go, in main or in testSubClass.cpp in the testSubClass constructor?

Assuming you have something like Ui::testClass ui;, then ui.setupUi(this) goes in the constructor of the subclass, meaning testSubClass.

The multiple inheritance approach assumes you subclass QMainWindow but also Ui::testClass. Then you have direct access to it's members.

Regards

illuzioner
24th June 2007, 03:21
You can choose between either the single inheritance approach or the multiple inheritance approach. You can read about both of them in the documentation.

Single inheritance:

For this case is a subclass of QMainWindow and contains a member of type Ui::testClass( this is the one generated by uic ).

Right there...

Assuming you have something like Ui::testClass ui;, then ui.setupUi(this) goes in the constructor of the subclass, meaning testSubClass.

The multiple inheritance approach assumes you subclass QMainWindow but also Ui::testClass. Then you have direct access to it's members.

Regards

hi, thanks for the reply. i read all the documentation multiple times, but it is sparse and does not give complete examples, just snippets, and it's especially useless for mainwindows using multiple inheritance. the docs don't discuss the advantages or disadvantages of either approach.

single inheritance is the approach i was taking for converting things to qt4, but the single inheritance approach doesn't seem correct or in line with the way i worked things in qt3. as a subclass, i had access to all members of the base class, which is a necessity. with this single inheritance, i'd have to do so much reprogramming to point to the right members i'd rather become a monk.

honestly i don't even see the benefit of the single inheritance approach. it looks like i have to have the multiple inheritance.

so, i know how to inherit from both classes, but how do the ui::setup commands change for multiple inheritance?
is there any drawback to using multiple inheritance?

thanks again! -- lou

marcel
24th June 2007, 05:16
so, i know how to inherit from both classes, but how do the ui::setup commands change for multiple inheritance?
is there any drawback to using multiple inheritance?

Well, it changes to setupUi(this), since you inherit the class now, and it is not a member anymore.

Regards.