Results 1 to 5 of 5

Thread: How to call a function in the mother object from a child object?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to call a function in the mother object from a child object?

    Add a pointer of your parent class in your child class, change the constructors to pass the parent pointer. Once you have the parent pointer inside child you can easily access any public method of parent.

  2. The following user says thank you to nish for this useful post:


  3. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to call a function in the mother object from a child object?

    You can do this, but it makes the parent-child system highly coupled. This is not a good situation to be in as the design is not flexible, and is not modular. Now you cannot use your child component anywhere - it must be used with only specific parents.

    When this happens you should be looking at doing some dependency inversion
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  4. The following user says thank you to amleto for this useful post:


Similar Threads

  1. Function call from a NULL this object ?
    By Computer Hater in forum Qt Programming
    Replies: 3
    Last Post: 24th September 2011, 16:07
  2. cannot call member function without object
    By been_1990 in forum Qt Programming
    Replies: 11
    Last Post: 23rd October 2010, 17:12
  3. Replies: 2
    Last Post: 7th July 2009, 17:44
  4. Cannot call function without object
    By Salazaar in forum Newbie
    Replies: 5
    Last Post: 11th June 2007, 14:55
  5. Replies: 3
    Last Post: 16th May 2007, 11:07

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.