PDA

View Full Version : Y is className a member function rather than a static one ?



sunil.thaha
15th September 2006, 11:44
Y have trolltech declared className() as a member function rather than a static function ?

jacek
15th September 2006, 12:13
Y have
Please, don't use such ugly abbreviations.


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

QString name( SomeClass::className() );
Or you can write simply:

QString name( "SomeClass" );
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:

BaseClass *base = new SomeClassDerivedFromBase();
qDebug() << base->className();
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().

sunil.thaha
15th September 2006, 12:33
Please, don't use such ugly abbreviations. Beauty lies in the eyes of the viewer ;). Anyway I will take care.




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... :rolleyes:

jacek
15th September 2006, 13:41
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()".

Chicken Blood Machine
17th September 2006, 20:50
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...

sunil.thaha
15th December 2006, 09:57
FYI:
There is a undocumented staticMetaObject which is a public datamember in Qt 4.1.x and IT is documented in Qt 4.2

wysota
15th December 2006, 12:20
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 :)

Chicken Blood Machine
12th January 2007, 01:43
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.