Results 1 to 8 of 8

Thread: Y is className a member function rather than a static one ?

  1. #1
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Y is className a member function rather than a static one ?

    Y have trolltech declared className() as a member function rather than a static function ?
    We can't solve problems by using the same kind of thinking we used when we created them

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Y is className a member function rather than a static one ?

    Quote Originally Posted by sunil.thaha
    Y have
    Please, don't use such ugly abbreviations.

    Quote Originally Posted by sunil.thaha
    ... declared className() as a member function rather than a static function ?
    Because it wouldn't make sense. You need className() when you don't know the class name.

    If className() was static, you would have to use it like this:
    Qt Code:
    1. QString name( SomeClass::className() );
    To copy to clipboard, switch view to plain text mode 
    Or you can write simply:
    Qt Code:
    1. QString name( "SomeClass" );
    To copy to clipboard, switch view to plain text mode 
    The effect is the same and in either case you will have to change your code when you rename your class. The only difference, is that in former case you won't make a typo.

    Now consider this:
    Qt Code:
    1. BaseClass *base = new SomeClassDerivedFromBase();
    2. qDebug() << base->className();
    To copy to clipboard, switch view to plain text mode 
    With inheritance mechanism, you can have a pointer that points to an instance of some class derived from a base class, but you not necessarily have to know which one and that's when you have to invoke className().

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

    sunil.thaha (15th September 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is className a member function rather than a static one ?

    Quote Originally Posted by jacek
    Please, don't use such ugly abbreviations.
    Beauty lies in the eyes of the viewer . Anyway I will take care.


    Quote Originally Posted by jacek
    Because it wouldn't make sense. You need className() when you don't know the class name.


    With inheritance mechanism, you can have a pointer that points to an instance of some class derived from a base class, but you not necessarily have to know which one and that's when you have to invoke className()
    That makes sense.
    But I did not find the virual keyword in the assistant. That would have given the clue...
    We can't solve problems by using the same kind of thinking we used when we created them

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why is className a member function rather than a static one ?

    Quote Originally Posted by sunil.thaha
    But I did not find the virual keyword in the assistant.
    It isn't virtual in Qt4, because it's a part of Qt3 Support module and a shorthand for "metaObject()->className()".

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

    sunil.thaha (18th September 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Y is className a member function rather than a static one ?

    Quote Originally Posted by jacek View Post
    Please, don't use such ugly abbreviations.
    Hear! hear! At last someone finally said it. Bastardizations of the English language such as 'U', 'Y', 'UR' '4" '2', etc. etc. are just ignorant and lazy (unless of course you are using a mobile phone, where it really is quicker and only the recipient has to tolerate the sloppy use of language).

    Just had to get that off my chest...
    Save yourself some pain. Learn C++ before learning Qt.

  8. #6
    Join Date
    Jan 2006
    Location
    Kerala
    Posts
    371
    Thanks
    76
    Thanked 37 Times in 32 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Y is className a member function rather than a static one ?

    FYI:
    There is a undocumented staticMetaObject which is a public datamember in Qt 4.1.x and IT is documented in Qt 4.2
    We can't solve problems by using the same kind of thinking we used when we created them

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

    Default Re: Y is className a member function rather than a static one ?

    Quote Originally Posted by Chicken Blood Machine View Post
    Hear! hear! At last someone finally said it. Bastardizations of the English language such as 'U', 'Y', 'UR' '4" '2', etc. etc. are just ignorant and lazy (unless of course you are using a mobile phone, where it really is quicker and only the recipient has to tolerate the sloppy use of language).

    Just had to get that off my chest...
    As you may have noticed we try to keep the language used clean and we ourselves try to use British English whenever possible, which in my opinion is much more pure than American English, which also explains why this site is called Qt Centre and not Qt Center
    Last edited by wysota; 15th December 2006 at 11:25.

  10. #8
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Thanked 42 Times in 37 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Y is className a member function rather than a static one ?

    As much as I enjoy besmirching American English, there's nothing really pure about British English. It's a mishmash of various languages with as many exceptions as it has rules. It is also inconsistent in many places. Anyone who has become fluent in it as a second language has achieved a lot as far as I'm concerned.
    Save yourself some pain. Learn C++ before learning Qt.

Similar Threads

  1. use qpsql
    By raphaelf in forum Installation and Deployment
    Replies: 34
    Last Post: 22nd August 2006, 12:52
  2. Qt 4.1.4 plugin QPSQL
    By jcr in forum Installation and Deployment
    Replies: 4
    Last Post: 22nd June 2006, 22:55
  3. I got two problems when I used static compiled library of QT4
    By qintm in forum Installation and Deployment
    Replies: 8
    Last Post: 20th April 2006, 08:52
  4. Qt 4.1 and KDE 3.5.1 on OSX 10.2.8
    By Ptero-4 in forum Installation and Deployment
    Replies: 6
    Last Post: 6th February 2006, 02:44
  5. Replies: 25
    Last Post: 15th January 2006, 00:53

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.