PDA

View Full Version : Ui interface and its connected implementation



Yayati.Ekbote
4th February 2010, 09:56
Hi!!

I am having a serious problem with QT designing. When i draw widgets on the form in say xyz.ui file. these widgets don't get connected to the code i write in xyz.h file and xyz.cpp file.

The widgets which are drawn on the form have no use. When in implementation file i initialise QPushButton *button = new QPushButton(tr("New"));
a new button appears on the form with the old button drawns on the xyz.ui file in the back. Why does this happen? Do i have to link the individual button interface to its code in implementation file explicitly? If yes then how? if no then what to do??
Plz guide!!

Lesiok
4th February 2010, 10:36
Why You create new widgets "manually" in implementation code ?
Please show Yours code (h and cpp files).

mrvk
4th February 2010, 10:59
Are you sure, you have used the connect method properly to connect the widgets in your UI to the slots defined in your cpp file
Check
http://qt.nokia.com/doc/4.6/qobject.html#connect-2

In case you do not wish to explicitly connect, take a look at

http://qt.nokia.com/doc/4.6/qmetaobject.html#connectSlotsByName

Hope it helps

coderbob
4th February 2010, 13:36
Hi!!

I am having a serious problem with QT designing. When i draw widgets on the form in say xyz.ui file. these widgets don't get connected to the code i write in xyz.h file and xyz.cpp file.

The widgets which are drawn on the form have no use. When in implementation file i initialise QPushButton *button = new QPushButton(tr("New"));
a new button appears on the form with the old button drawns on the xyz.ui file in the back. Why does this happen? Do i have to link the individual button interface to its code in implementation file explicitly? If yes then how? if no then what to do??
Plz guide!!

If you are loading the ui file and using it as a widget try the following:



QPushButton *button = qFindChild<QPushButton *>(QUiLoader::load("xyz.ui"), "name_of_your_button_in_your_ui_file");

Edit: Of course the return widget from QUiLoader is going to be needed elsewhere and should be saved and only referenced instead of single called and thrown away in the example.

Bob