PDA

View Full Version : plz teach inheritance



vinayaka
28th May 2011, 08:29
hai,
some one plz teach me inheritance in qt. i know basic is c++. i went through it. but i am unable to implement them in qt. how to use functions in them. Is it possible to use Super keyword in qt. how can we pass string, int from base class to derived class. (plz don't say to go through calculator ex:, i already went through it;))

Santosh Reddy
28th May 2011, 08:54
Ok vinayaka,

I am replying only to encourage you to know what you don't know (or may you should you)


some one plz teach me inheritance in qt.
no one can teach you "inheritance in qt", because "inheritance" in one of the powerful features which Qt uses from C++ (learn C++ for inheritance)


i know basic is c++. i went through it. but i am unable to implement them in qt. how to use functions in them.
If you know basics in C++, than you should know about inheritance, Qt only uses (exploits) them. If you know what inheritance is all about, then you will eventually know how to use functions in them.


Is it possible to use Super keyword in qt.
No (as far as I know Qt, or yet)


how can we pass string
First understand what is cstring, std::string and then QString is. (by then you will know how stupid you question is)


(plz don't say to go through calculator ex:, i already went through it)
may be you went thought calculator ex, but you never understood it? (that is the reason)

Once again I replayed not to discourage you, but only to make you understand what you don't know (or may be you should know).

wysota
28th May 2011, 08:54
Qt is not a language. Qt is C++. Anything that goes in C++, goes in Qt. Thus you can't use the "super" keyword in Qt because there is no such keyword in C++. If you understand inheritance in C++, there is nothing else you need to learn about it to be able to use it with Qt.

Zlatomir
28th May 2011, 08:58
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)
}

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.

vinayaka
28th May 2011, 09:05
thanx santosh. its really an encouragement.:)
What you said is right, still i am not able to understand calculator .
I will try again to implement inheritance as i know after search and study.:cool:

wysota
28th May 2011, 09:08
You don't "implement inheritance", you use it. Like when building a house you "use" a hammer and not "implement" or "make" it.

vinayaka
28th May 2011, 09:25
ok.I will do my best to use it. :)

Added after 11 minutes:

ThanK U Zlatomir..........lots of thanx:):):)

Santosh Reddy
28th May 2011, 11:03
Anything that goes in C++, goes in Qt. Thus you can't use the "super" keyword in Qt because there is no such keyword in C++.
I agree that Anything that goes in C++, goes in Qt, but I don't completely agree with later statement


Thus you can't use the "super" keyword in Qt because there is no such keyword in C++
There are keywords (at-least I call them so) in Qt which C++ does not support like "signals", "slots" (who knows in future versions of Qt "super" may also is supported (may be with different meaning)).

Yes, I still agree with the overall meaning of the post, that there is no such keyword "super" in Qt (implied in C++)

stampede
28th May 2011, 11:29
There is nothing to agree or disagree here, the list of C++ keywords (reserved identifiers) is clearly defined: C++ keywords (http://www.cppreference.com/wiki/keywords/start)

squidge
28th May 2011, 12:28
Calling words like 'signals' keywords is incorrect IMO, they are just macros. Words like 'emit' are completely optional (they are syntactic sugar). Other words are only needed by moc and are removed by the C++ preprocessor.

wysota
28th May 2011, 18:19
There are keywords (at-least I call them so) in Qt which C++ does not support like "signals", "slots" (who knows in future versions of Qt "super" may also is supported (may be with different meaning)).
A "keyword" is something related to syntax of the language and interpreted by the compiler of that language. Since Qt is not a language, it can't introduce keywords for the C++ compiler. I can agree that things like "signals:" and "slots:" can be treated as keywords of moc.