View Full Version : connect

26th May 2006, 23:41
Hi, I've this problem; I need to connect a signal to a SLOT of myMainForm...How to do this? What's the best way to do this? thanks

void myDialog::init() {
myMainForm* myw; //how obtain this
connect(buttonGroupLL, SIGNAL(clicked(int)), myw, SLOT(activeTab(int)));

27th May 2006, 02:18
Keep a pointer to this widget as a member of the dialog class and initialise it in the constructor of a dialog. Alternatively, if the widget is a parent of the dialog, you can use parent() call to retrieve it.

27th May 2006, 10:13
sorry, the problem is that function init() is inside a dialog.ui.h (create from designer).....
it hasn't parent...(I think)

27th May 2006, 10:39
furthermore, I need that mydialog.ui.h can see the state button of myainForm and viceversa....

27th May 2006, 11:02
You won't be able to do it with .ui.h. You have to subclass and reimplement the constructor. Remember that using "ui.h" is deprecated and that it is only a hack to avoid the need to subclass in common situations.

27th May 2006, 11:13
1. why is it deprecated?
2.is it right create a dialog.ui.h from designer (leave that file empty) and sublcass it (and write code only here). Or which is the right way? thanks a lot

27th May 2006, 11:35
You dont must create any *.ui.h files ! ;) Actually Wysota explaine you upper why :)
Now do this things :]
- create form in Designer, set his name as FormBase and save it ;
- add this form to your project and create class Form that will be inherit your FormBase;
- use all members of FormBase in your Form class;

Have you understand ;)

27th May 2006, 11:40
no I haven't understand. In designer if I create a form(dialog?), when I save it, its extension is .ui! How don't create .ui???

27th May 2006, 11:43
You dont must create ui.h

27th May 2006, 12:01
if I save dialog from designer automatically a .ui.h is created.....

27th May 2006, 12:36
No. ui.h files are created when you enter some code into the form. And you're first asked if you want one to be created for you.

Anyway, that's all not the point. You can use .ui.h files if you insist to, but you need to subclass the class created by designer+uic anyway.

27th May 2006, 13:09
Keep a pointer to this widget as a member of the dialog class and initialise it in the constructor of a dialog.
yes, I made this.

myMainForm* _myw;

myLightDialog::myLightDialog( QWidget* parent, const char* name, bool modal, WFlags fl )
:lightDialog (parent, name, modal, fl), _myw ( ????)( {
Actually mymainForm isn't parent of myLightDialog...

27th May 2006, 13:22
So pass a pointer to it in the constructor.

You are posting in Qt programming section of the forum, I assume you know C++ basics, don't you? This issue doesn't have anything to do with Qt. It's a simple C++ issue of storing a pointer to an object as a class member.