Results 1 to 9 of 9

Thread: get Parent Pointer

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default get Parent Pointer

    Hello everybody,

    QT:4.1.1

    How could i get my parent Pointer?

    I tryed this:
    login.cpp
    Qt Code:
    1. (MainWindow*)parent).insertTables();
    To copy to clipboard, switch view to plain text mode 

    ERROR:
    Qt Code:
    1. login.cpp:63: error: argument of type `QObject*(QObject::)() const' does not mat
    2. ch `MainWindow*'
    To copy to clipboard, switch view to plain text mode 

    I want to get the pointer to call a function of MainWindow. I open LoginDialog like this:
    Qt Code:
    1. void MainWindow::openLoginDialog()
    2. {
    3. LoginDialog l(this);
    4. l.exec();
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    Have somebody a idea how to get the Parent Pointer?
    Think DigitalGasoline

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: get Parent Pointer

    Try:
    Qt Code:
    1. ((MainWindow*)parent())->insertTables();
    To copy to clipboard, switch view to plain text mode 

    and how ugly is that...

  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: get Parent Pointer

    Hi JPN!
    Are this forum a F1 Competition?
    I get a solution in just 2 minutes?

    I LOVE THIS FORUM

    Thank you!
    Think DigitalGasoline

  4. #4
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: get Parent Pointer

    Quote Originally Posted by raphaelf
    Are this forum a F1 Competition?
    yes man championatsip is started
    a life without programming is like an empty bottle

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: get Parent Pointer

    Quote Originally Posted by jpn
    Try:
    Qt Code:
    1. ((MainWindow*)parent())->insertTables();
    To copy to clipboard, switch view to plain text mode 

    and how ugly is that...
    A less ugly one would be:

    Qt Code:
    1. MainWindow *p = qobject_cast<MainWindow*>(parent());
    2. if(p){
    3. // ...
    4. }
    To copy to clipboard, switch view to plain text mode 
    or even
    Qt Code:
    1. MainWindow *p = dynamic_cast<MainWindow*>(parent());
    2. if(p){
    3. // ...
    4. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: get Parent Pointer

    Or using signal/slot mechanism so that dialog wouldn't need to even know about some "MainWindow".. Who knows

  7. #7
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: get Parent Pointer

    Hi ZLAKO, Hi wysota...

    Thanks for repiles

    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
    Think DigitalGasoline

  8. #8
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: get Parent Pointer

    JPN: Have you a finish example for what you mean?
    Think DigitalGasoline

  9. #9
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: get Parent Pointer

    Quote Originally Posted by raphaelf
    Hi ZLAKO, Hi wysota...

    Thanks for repiles

    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
    start new thread in Feedback section
    a life without programming is like an empty bottle

Similar Threads

  1. Dragging a pointer
    By Cruz in forum Qt Programming
    Replies: 4
    Last Post: 10th July 2009, 03:51
  2. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 18:14
  3. parent() heirarchy misunderstanding?
    By KShots in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2007, 18:18
  4. Convert Windows "HWND" to QWidget* pointer?
    By gerome69 in forum Qt Programming
    Replies: 4
    Last Post: 20th September 2006, 13:03
  5. Referencing Parent Widget from Child
    By taylor34 in forum Qt Programming
    Replies: 8
    Last Post: 11th April 2006, 15:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.