Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A custom class, a copy constructor and a warning
QtWS25 Last Chance

A custom class, a copy constructor and a warning

Scheduled Pinned Locked Moved Solved General and Desktop
mingw32copycompilerwarning
3 Posts 2 Posters 2.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 8 Feb 2018, 07:48 last edited by
    #1

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

    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 8 Feb 2018, 08:05 last edited by
      #2

      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

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      J 1 Reply Last reply 8 Feb 2018, 08:12
      5
      • V VRonin
        8 Feb 2018, 08:05

        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

        J Offline
        J Offline
        J.Hilk
        Moderators
        wrote on 8 Feb 2018, 08:12 last edited by
        #3

        @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!


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        0

        2/3

        8 Feb 2018, 08:05

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved