Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

A custom class, a copy constructor and a warning


  • Moderators

    Hello everyone,

    I'm currently in the process of cleaning up my code and I stumbled over a particular compiler warning:

    base class 'class QObject' should be explicitly initialized in the copy constructor
    Datagram::Datagram(const Datagram &data)
    

    I only have QObject as a base class, to define enums in it and to register is as a Metaobject.
    I need to pass it around via Signal&Slots and a QueuedConnection.

    I do not explicitly initalize QObject in the different constructors either.

    The warning is only there with the mingw-compiler, msvc and clang have no problems with it.

    So how would I do that?

    heres my copy constructor:

    Datagram::Datagram(const Datagram &data)
    {
        m_data = data.m_data;
        m_Type = data.m_Type;
    }
    


  • I only have QObject as a base class, to define enums in it and to register is as a Metaobject.

    That's what Q_GADGET is for. Remove the base class and replace Q_OBJECT with Q_GADGET


  • Moderators

    @VRonin Well apparently it is oO.
    Wasn't ware of that one, I came by it when googled the warning, but gave it not much mind.

    Thank you!