Results 1 to 5 of 5

Thread: Parental issues

  1. #1
    Join Date
    Nov 2006
    Posts
    41
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Parental issues

    I want to access a functional member of a parent widget from it's child widget, the way i was doing is like
    from the child widget
    Qt Code:
    1. this->parentWidget()->publicMethod();
    To copy to clipboard, switch view to plain text mode 
    but the compiler says "class QWidget has no member named publicMethod"
    so, how can i access the public method of the parent?

    I have checked that parentWidget() returns the pointer to the parent widget with the objectName() property so i have parented the child correctly
    thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Parental issues

    Either use signals & slots mechanism or cast the value returned by parentWidget() to a proper type.

  3. The following user says thank you to jacek for this useful post:

    chaosgeorge (11th November 2006)

  4. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Parental issues

    I have a doubt...
    arent parent public methods directly accesible to the child class ??
    I mean if u are inheriting from a parent class, its function should be accessible from the child class , isnt it?

  5. #4
    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: Parental issues

    Quote Originally Posted by aamer4yu View Post
    I have a doubt...
    arent parent public methods directly accesible to the child class ??
    I mean if u are inheriting from a parent class, its function should be accessible from the child class , isnt it?
    QObject's parent-child relationship is a different concept than C++ inheritance.

    Edit: here's an interesting article about the subject. A short quote from the article:
    Parent Objects versus Base Classes
    Parent objects should not be confused with base classes. The parent-child relationship is meant to describe containment, or management, of objects at runtime. The base-derived relationship is a static relationship between classes determined at compile-time.
    It is possible that a parent can also be an instance of a base class of some of its child objects. These two kinds of relationships are distinct and must not be confused, especially considering that many of our classes will be derived directly or indirectly from QObject.
    Last edited by jpn; 12th November 2006 at 15:22. Reason: updated contents
    J-P Nurmi

  6. #5
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Parental issues

    Thanx fr clearing the confusion

Similar Threads

  1. Layout Management Issues
    By dave in forum Newbie
    Replies: 3
    Last Post: 5th November 2006, 18:16
  2. MySql plugin driver issues
    By stevey in forum Installation and Deployment
    Replies: 11
    Last Post: 20th September 2006, 13:45
  3. Issues regarding QMySql drivers and mysql database
    By bera82 in forum Qt Programming
    Replies: 2
    Last Post: 10th August 2006, 17:50
  4. QTextEdit issues
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 18th July 2006, 08:00
  5. Two QDate issues
    By GreyGeek in forum Qt Programming
    Replies: 2
    Last Post: 8th March 2006, 02:09

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.