Inheritance doesn't have many new things in Qt (compared to the one in C++), maybe you confuse stuff like for example when you inherit from QWidget to create your own Widget class you need to add the Q_OBJECT macro (but this things are not really related to inheritance)
To inherit in C++ you don't use the "Super" keyword (that sounds like a Java keyword ), you just have the classes something like:
class BaseClass {
public:
BaseClass(int i = 10) : member(i){}
int getMember() {return member;}
private:
int member;
}
class DerivedClass : public BaseClass //you usually need public inheritance
{
//you can't use the member directly here (since it is private), you can only use the members declared as protected
//but you can use the getMember function (because it is public) to return the value
//also you can code constructors that pass parameters to the base class constructor (with Qt you usually pass the parent pointer this way)
}
class BaseClass {
public:
BaseClass(int i = 10) : member(i){}
int getMember() {return member;}
private:
int member;
}
class DerivedClass : public BaseClass //you usually need public inheritance
{
//you can't use the member directly here (since it is private), you can only use the members declared as protected
//but you can use the getMember function (because it is public) to return the value
//also you can code constructors that pass parameters to the base class constructor (with Qt you usually pass the parent pointer this way)
}
To copy to clipboard, switch view to plain text mode
But you can read a book about C++, like: Thinking in C++ written by Bruce Eckel are two free volumes (in electronic format) and after you get comfortable with C++ you will see the Qt doesn't change inheritance.
Bookmarks