Results 1 to 8 of 8

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

Threaded View

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

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

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

    sunil.thaha (15th September 2006)

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
  •  
Qt is a trademark of The Qt Company.