PDA

View Full Version : Problem with QDialog class



sudheer168
22nd December 2008, 05:08
Hi ,I am using Qt 4.4.0 .In my application I want to access the members/variables of one dialog class in another dialog class.Now I am able to access the variables/members of Mainwindow class in any other dialog.The code i used to access is shown below




MainWindow *omans = qobject_cast<MainWindow *>(parentWidget());
omans->natimer->stop();



I wrote the above code in other dialog class to access the "natimer " which i was declared in mainwindow.
Now I want to access the member of one dialog class in another dialog class.
I tried the same code to access the member of one dialog class in another dialog class,but the execution get breaks .
So help me to solve the problem.

With Regards,
Sudheer.

caduel
22nd December 2008, 07:21
You have to cast the window to the type of your class (not just to a QMainWindow).
A QMainWindow does not exhibit that timer.
(You might also prefer not to access internals of your class like that. How about adding a slot "stopTimer()" to your class?)

HTH

aamer4yu
22nd December 2008, 10:58
@Caduel, his class is MainWindow, not QMainWindow.

@Sudheer

I tried the same code to access the member of one dialog class in another dialog class,but the execution get breaks .

Can u show that relevant code ?

caduel
22nd December 2008, 11:02
right you are :o

(The error might be that (due to a missing Q_OBJECT in the class decl of MainWindow) the qobject_cast returns NULL.)

sudheer168
23rd December 2008, 09:03
Thanks for your kind replies .

With Regards,
Sudheer.