Why does QObject disable copy constructors and assignment operators?

Time:2021-3-16

QObject disable copy constructors and assignment operators because of its properties:

  1. May have a unique QObject:: objectname.
    The QT object can have its own name, and the objectname property holds the name of the object.
    How to deal with the name of a new object when copying a QT object?
  2. Has a position in the object hierarchy.
    Qobjects organizes itself in an object tree.
    If you copy a QT object, where should the new object be located?
  3. You can connect to other QT objects to signal to them or to receive signals from them.
    Qobjects can connect to other objects.
    How to transfer these connections to a new object when copying a QT object?
  4. New properties that are not declared in C + + classes can be added at run time.
    If you copy a QT object, should the attributes added in the original object be copied to the new object?

For these reasons, QT objects should be treated as identities rather than values. Therefore, the copy constructor and assignment operator of QObject are disabled.