PDA

View Full Version : get Parent Pointer



raphaelf
3rd March 2006, 12:42
Hello everybody,

QT:4.1.1

How could i get my parent Pointer?

I tryed this:
login.cpp


(MainWindow*)parent).insertTables();


ERROR:


login.cpp:63: error: argument of type `QObject*(QObject::)() const' does not mat
ch `MainWindow*'


I want to get the pointer to call a function of MainWindow. I open LoginDialog like this:


void MainWindow::openLoginDialog()
{
LoginDialog l(this);
l.exec();

}


Have somebody a idea how to get the Parent Pointer?

jpn
3rd March 2006, 12:45
Try:

((MainWindow*)parent())->insertTables();

and how ugly is that... :)

raphaelf
3rd March 2006, 12:50
Hi JPN!
Are this forum a F1 Competition?
I get a solution in just 2 minutes?

I LOVE THIS FORUM :p

Thank you!

zlatko
3rd March 2006, 12:52
Are this forum a F1 Competition?


yes man championatsip is started :D

wysota
3rd March 2006, 12:53
Try:

((MainWindow*)parent())->insertTables();

and how ugly is that... :)

A less ugly one would be:


MainWindow *p = qobject_cast<MainWindow*>(parent());
if(p){
// ...
}
or even

MainWindow *p = dynamic_cast<MainWindow*>(parent());
if(p){
// ...
}

jpn
3rd March 2006, 12:57
Or using signal/slot mechanism so that dialog wouldn't need to even know about some "MainWindow".. Who knows :)

raphaelf
3rd March 2006, 12:58
Hi ZLAKO, Hi wysota...

Thanks for repiles :p

Would be a idea to set a statistic on qcentre.org with the top 10 "fast for furious QT guys" :)

I cant live without qtcentre!
this forum are my gasoline :p

raphaelf
3rd March 2006, 13:07
JPN: Have you a finish example for what you mean?:rolleyes:

zlatko
3rd March 2006, 14:09
Hi ZLAKO, Hi wysota...

Thanks for repiles :p

Would be a idea to set a statistic on qcentre.org with the top 10 "fast for furious QT guys" :)

I cant live without qtcentre!
this forum are my gasoline :p

start new thread in Feedback section ;)