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. Problems with object design, how to get over ambiguous warnings.
Forum Updated to NodeBB v4.3 + New Features

Problems with object design, how to get over ambiguous warnings.

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 864 Views 2 Watching
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    In my original design I have created classes with are derived from Qt base widget classes and these derived classes have a common node member.

    Now I am changing the design as there are elements in the node which would benefit if the node class was a base class with pure virtual functions that would be defined in the derived widget classes.

    For example, originally:

        class clsQtPushBtn : public QPushButton {
        Q_OBJECT
            friend class clsXMLnode;
    
        private:
            clsXMLnode* mpobjNode;
        ...
    

    Now, the new design is cleaner and more powerful:

    class clsQtPushBtn : public QPushButton, clsXMLnode {
    Q_OBJECT
    ...
    

    The issue I'm getting now is when I try to compile I see:

    moc_clsQtPushBtn.cpp:78:21: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject':
        class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject
        class clsQtPushBtn -> class clsXMLnode -> class QObject
        return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
                        ^~~~~
    moc_clsQtPushBtn.cpp:78:50: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject':
        class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject
        class clsQtPushBtn -> class clsXMLnode -> class QObject
        return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
                                                     ^~~~~
    

    Is there anyway to solve this?

    One possible cause could be that in the original design which I haven't change yet:

    class clsXMLnode : public QObject {
    Q_OBJECT
    ....
    

    Would removing Q_OBJECT and not deriving from QObject help?

    Kind Regards,
    Sy

    JonBJ 1 Reply Last reply
    0
    • SPlattenS SPlatten

      In my original design I have created classes with are derived from Qt base widget classes and these derived classes have a common node member.

      Now I am changing the design as there are elements in the node which would benefit if the node class was a base class with pure virtual functions that would be defined in the derived widget classes.

      For example, originally:

          class clsQtPushBtn : public QPushButton {
          Q_OBJECT
              friend class clsXMLnode;
      
          private:
              clsXMLnode* mpobjNode;
          ...
      

      Now, the new design is cleaner and more powerful:

      class clsQtPushBtn : public QPushButton, clsXMLnode {
      Q_OBJECT
      ...
      

      The issue I'm getting now is when I try to compile I see:

      moc_clsQtPushBtn.cpp:78:21: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject':
          class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject
          class clsQtPushBtn -> class clsXMLnode -> class QObject
          return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
                          ^~~~~
      moc_clsQtPushBtn.cpp:78:50: error: ambiguous conversion from derived class 'const clsQtPushBtn' to base class 'QObject':
          class clsQtPushBtn -> class QPushButton -> class QAbstractButton -> class QWidget -> class QObject
          class clsQtPushBtn -> class clsXMLnode -> class QObject
          return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
                                                       ^~~~~
      

      Is there anyway to solve this?

      One possible cause could be that in the original design which I haven't change yet:

      class clsXMLnode : public QObject {
      Q_OBJECT
      ....
      

      Would removing Q_OBJECT and not deriving from QObject help?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @SPlatten
      Start by reading through the following post in this forum: https://forum.qt.io/topic/88295/with-qt-5-6-is-it-possible-to-avoid-the-diamond-problem-when-signals-and-slots-are-defined-in-two-branches

      1 Reply Last reply
      2
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        Thanks, I think I'll have to keep the original design and look for another way to simplify things.

        Kind Regards,
        Sy

        kshegunovK 1 Reply Last reply
        0
        • SPlattenS SPlatten

          Thanks, I think I'll have to keep the original design and look for another way to simplify things.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          @SPlatten said in Problems with object design, how to get over ambiguous warnings.:

          Thanks, I think I'll have to keep the original design and look for another way to simplify things.

          Aggregate instead. Your button isn't a node to begin with, so here the multiple inheritance is even ideologically wrong. If you have a class Car it shouldn't inherit from SteeringWheel and Engine, the car is not an engine, nor is it a steering wheel. It has an engine on the other hand.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          5
          • SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

            Your thinking depends on the granularity of the design. My design is that every thing is a node must like in OOP everything is an object.

            Kind Regards,
            Sy

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              You simply can't derive from QObject two times - fix your design.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • SPlattenS Offline
                SPlattenS Offline
                SPlatten
                wrote on last edited by
                #7

                I was never trying to do that anyway.

                Kind Regards,
                Sy

                1 Reply Last reply
                0

                • Login

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