PDA

View Full Version : Not accessing widget outside the class



santosh.kumar
18th May 2007, 06:38
Hi
i m creating one dialog using designer...dialog conatins one treeWidget.
I m making this this dialog as public...

Ui::Dialog dlg;

In the construtor i m calling setupUi(this); its working....

but i want to use this treeWidget in other class...i m using obj of this class...

obj->dlg.treeWidget in other class...but its not working...where m i missing...

marcel
18th May 2007, 07:02
Well, how exactly are you using it? Is it in other thread?
Is the dialog created( setupUi and all ) when you use it?
Could you post some relevant code?

santosh.kumar
18th May 2007, 07:48
some code for this ...
//first file
#include "ui_Dialog.h"

Header file
public:
Ui::Dialog dlg;

cpp file
Constructor part of FIRST class
{
dlg.setupUi(this);
dlg.treeWidget->setColumnCount(2);
}

///Second class
header class
private:
FIRST *first;
//cpp file
void SECOND::func()
{
QTreeWidgetItem *pItem = NULL;
pItem = new QTreeWidgetItem(first->dlg.treeWidget);
pItem->setText(0,"root");
}


///But is not connecting to the FIRST class...not display text "root" in treeWidget ...why

marcel
18th May 2007, 07:56
The problem is that you did not instantiate FIRST in the SECOND class.
You have to create FIRST to be able to use it like that. Something like:
first = new FIRST();

santosh.kumar
18th May 2007, 07:59
i already instantialted like this in my class

first = new FIRST();
still it is not working....

marcel
18th May 2007, 08:05
In the constructor of FIRST:
it is setupUi( this ) not dlg.setupUi( this ).

If you get any errors after replacing that, please post them

jacek
18th May 2007, 12:57
still it is not working....
What does "not working" exactly mean in this case? Does it compile?


In the constructor of FIRST:
it is setupUi( this ) not dlg.setupUi( this ).
The original version was OK, as santosh.kumar uses the single inheritance approach.