Why is it not allowed to copy QObjects?

The reason it is not possible to copy QObjects [doc.qt.nokia.com] is that QObject is a polymorphic object, and that polymorphic objects cannot be copied.

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

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

No comments

Write a comment

Sorry, you must be logged in to post a comment.