From 10:00 CET Friday 22nd November we will adjust how the server works to deal with some recently reported problems. Therefore there may be a load problem, if you experience more problems than usual trying to access the forum then please PM AndyS or any of the moderators so they can inform me.


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;
    }
    

  • Qt Champions 2018

    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!