PDA

View Full Version : Access widgets



Gayathri
17th November 2006, 13:52
Hi,
Please let me know how to access widgets in other dialogs?

Thanks in advance

3dch
17th November 2006, 14:37
Easiest is to provide a pointer to the widget(s) in the dialog constructor and, for example, save the pointer in a member variable of your class which is derived from QDialog. This way all methods of your dialog class can access the widget(s).

Header file



class MyDialog : public QDialog
{
Q_OBJECT

public: // Operations

// ctor
MyDialog(QWidget* parent, QWidget* myOtherWidget);


private: // Attributes

QWidget* m_otherWidget;

....


Implementation file



MyDialog::MyDialog(QWidget* parent, QWidget* myOtherWidget)
: QDialog(parent),
m_otherWidget(myOtherWidget)
{
...

m_otherWidget->callWhateverMethodIsAccessibleFromThatWidget();

...
}


Ernst

jacek
17th November 2006, 14:37
Windows are just normal classes, so you can do it just like if you were accessing data stored in some other class.

Remember that usually you don't want to access other window's widgets directly, since it's an implementation detail that should be hidden from other classes.

Also read this: http://www.qtcentre.org/forum/f-newbie-4/t-how-to-use-searchscandiskdlgobj-4444.html and search the forum before you ask a question.