PDA

View Full Version : Parental issues



chaosgeorge
11th November 2006, 22:07
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


this->parentWidget()->publicMethod();

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

jacek
11th November 2006, 22:18
Either use signals & slots mechanism or cast the value returned by parentWidget() to a proper type.

aamer4yu
12th November 2006, 13:50
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?

jpn
12th November 2006, 16:15
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 (http://doc.trolltech.com/4.2/objecttrees.html) is a different concept than C++ inheritance.

Edit: here's an interesting article (http://www.informit.com/articles/article.asp?p=667415&rl=1) 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.

aamer4yu
13th November 2006, 05:10
Thanx fr clearing the confusion