Q_Disable_Copy Example

Q_Disable_Copy Example



In Qt there is a macro that allows declaring private copy constructurs and assignment operators for classes: http://qt-project.org/doc/qt-5.0/qtcore/qobject.html#Q_DISABLE_COPY. It is said that this macro should be used for all QObject (especially QWidget) derived classes.


Q_DISABLE_COPY_MOVE (Class) A convenience macro that disables the use of copy constructors, assignment operators, move constructors and move assignment operators for the given Class , combining Q_DISABLE_COPY and Q_DISABLE_MOVE. This function was introduced in Qt 5.13. See also Q_DISABLE_COPY and Q_DISABLE_MOVE..


This is by design. Actually, they are declared, but in a private section with the macro Q_DISABLE _COPY(). In fact, all Qt classes derived from QObject (direct or indirect) use this macro to declare their copy constructor and assignment operator to be private. The reasoning is found in the discussion on Identity vs Value on the Qt Object Model page.


©2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.


In my example , modified from the original, which is legal C++ there was: Test(const Test &obj):QObject(nullptr){ qDebug()<

Advertiser