[Qt-interest] QMetaObject::className() in constructors returns classname of baseclass

Niklas Wulf niklas at wulf-home.de
Fri May 28 19:36:21 CEST 2010


Hi Qties,

I have some class Foo, which inherits QObject and QDomDocument, and some other classes Bar, which inherit Foo.
Calling metaObject()->className() in Foo's constructor returns "Foo" even it's a instance of Bar.
Am I wrong?
Is this wanted behavior?
Much more important: Shouldn't this be documented?

greetings Niklas

class Foo() : public QObject, public QDomDocument {
Q_OBJECT
public:
	Foo(QObject* parent = 0) : QObject(parent), QDomDocument() { qDebug() << this->metaObject()->className(); }
	void test() { qDebug() << this->metaObject()->className(); }
};

class Bar : public Foo {
Q_OBJECT
public:
	Foo(QObject* parent = 0) : Foo(parent) {}
};

void main() {
	Foo* bar = new Bar(/*some QObject**/); //prints "Foo"
	bar.test(); //prints "Bar"
}



More information about the Qt-interest-old mailing list