copy constructor of derived QT class

前端 未结 2 599
难免孤独
难免孤独 2020-12-06 02:44

I have a class which is publicly inherited from QWidget:

class MyWidget : public QWidget
{
    Q_OBJECT
public:
    MyWidget(const MyWidget&         


        
2条回答
  •  醉梦人生
    2020-12-06 03:36

    QObject Class description page tells :

    QObject has neither a copy constructor nor an assignment operator. 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.

    That means you are not supposed to copy QT objects, since QObject is non-copyable by design.

    The first warning tells you to initialize the base class (which is QWidget). If you want to do this, you are going to construct a new base object, and I doubt that is what you want to do.

    The second error is telling you what I wrote above : do not copy qt objects.

提交回复
热议问题