Results 1 to 11 of 11

Thread: plz teach inheritance

  1. #1
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default plz teach inheritance

    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)

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: plz teach inheritance

    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).

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

    vinayaka (28th May 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: plz teach inheritance

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: plz teach inheritance

    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:
    Qt Code:
    1. class BaseClass {
    2. public:
    3. BaseClass(int i = 10) : member(i){}
    4. int getMember() {return member;}
    5. private:
    6. int member;
    7. }
    8.  
    9. class DerivedClass : public BaseClass //you usually need public inheritance
    10. {
    11. //you can't use the member directly here (since it is private), you can only use the members declared as protected
    12.  
    13. //but you can use the getMember function (because it is public) to return the value
    14.  
    15. //also you can code constructors that pass parameters to the base class constructor (with Qt you usually pass the parent pointer this way)
    16. }
    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.

  6. The following user says thank you to Zlatomir for this useful post:

    vinayaka (28th May 2011)

  7. #5
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: plz teach inheritance

    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.

  8. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: plz teach inheritance

    You don't "implement inheritance", you use it. Like when building a house you "use" a hammer and not "implement" or "make" it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. The following user says thank you to wysota for this useful post:

    vinayaka (28th May 2011)

  10. #7
    Join Date
    May 2011
    Posts
    120
    Thanks
    33
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: plz teach inheritance

    ok.I will do my best to use it.


    Added after 11 minutes:


    ThanK U Zlatomir..........lots of thanx
    Last edited by vinayaka; 28th May 2011 at 09:25.

  11. #8
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: plz teach inheritance

    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++)

  12. #9
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: plz teach inheritance

    There is nothing to agree or disagree here, the list of C++ keywords (reserved identifiers) is clearly defined: C++ keywords

  13. #10
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: plz teach inheritance

    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.

  14. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: plz teach inheritance

    Quote Originally Posted by Santosh Reddy View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. WizBang - Learn and Teach Procedural Programming Languages
    By chadkeck in forum Qt-based Software
    Replies: 1
    Last Post: 9th October 2009, 18:38
  2. inheritance
    By steiner in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2007, 21:17
  3. inheritance
    By mickey in forum General Programming
    Replies: 11
    Last Post: 28th September 2007, 22:54
  4. How much inheritance do you use?
    By Michiel in forum General Programming
    Replies: 8
    Last Post: 1st August 2006, 23:29
  5. QSA and inheritance
    By jwintz in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2006, 15:05

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.