Sections

Why is it not allowed to copy QObjects?

Entry number: 582 - Why is it not allowed to copy QObjects?

Answer:

The reason it is not possible to copy QObjects is that QObject is a polymorph object, and that
polymorph objects cannot be copied.

QPushButton pushButton;
QObject object = pushButton;
Q_ASSERT(object.metaObject() == &QPushButton::staticMetaObject).


This would assert, and all calls of virtual functions would call QObject's
implementation.


back

Patron of KDECustomers

Customers