Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Define Class dialog (questions) ?
Forum Updated to NodeBB v4.3 + New Features

Define Class dialog (questions) ?

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
11 Posts 3 Posters 535 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 7 Jan 2023, 16:46 last edited by
    #1
    1. What is the purpose of the "entry box" under pull down "Base class " ?
    2. I there a way to add multiple inheritance ?
    3. Is there a way to actually add <Custom > , my own class, to inherit from ?

    All while using "Define Class " dialog .

    b22cebea-c4b4-40b5-ac55-42de85292758-image.png

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Anonymous_Banned275
      wrote on 7 Jan 2023, 16:56 last edited by
      #2

      Partially solved , please ignore most of the original post - especially the <Custom> option questions.

      Here is an error I am not sure where is the issue .

      Should TEST_INHERITANCE_BASIC' also inherit from QObject ?

      /media/nov25-1/writable/BT_JAN7_SPP_CA/CCC_SOURCE/BT_SPP_CA/moc_test_inheritance_basic.cpp:78: error: ambiguous conversion from derived class 'const TEST_INHERITANCE_BASIC' to base class 'QObject':
      moc_test_inheritance_basic.cpp:78:21: error: ambiguous conversion from derived class 'const TEST_INHERITANCE_BASIC' to base class 'QObject':
      class TEST_INHERITANCE_BASIC -> class SUBCLASS_1 -> class QObject
      class TEST_INHERITANCE_BASIC -> class SUBCLASS_2 -> class QObject
      return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject;
      ^~~~~

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on 7 Jan 2023, 17:20 last edited by
        #3

        Is the answer somewhere here ??

        const QMetaObject *TEST_INHERITANCE_BASIC::metaObject() const
        {
        return QObject::d_ptr->metaObject ? QObject::d_ptr->dynamicMetaObject() : &staticMetaObject; ERROR HERE
        }

        void TEST_INHERITANCE_BASIC::qt_metacast(const char _clname)
        {
        if (!_clname) return nullptr;
        if (!strcmp(_clname, qt_meta_stringdata_TEST_INHERITANCE_BASIC.stringdata0))
        return static_cast<void
        >(this);
        if (!strcmp(_clname, "SUBCLASS_2"))
        return static_cast< SUBCLASS_2
        >(this);
        if (!strcmp(_clname, "QObject"))
        return static_cast< QObject*>(this); ERROR HERE
        return SUBCLASS_1::qt_metacast(_clname);
        }

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 7 Jan 2023, 17:44 last edited by Christian Ehrlicher 1 Jul 2023, 17:44
          #4

          When you use Q_OBJECT then yes, your class must derive from QObject somewhere in the inheritance tree - otherwise you get the errors above.

          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
          • A Offline
            A Offline
            Anonymous_Banned275
            wrote on 7 Jan 2023, 17:53 last edited by
            #5

            Mine class is defined this s way , and I get the error.

            #include <QObject>

            #include "subclass_1.h"
            #include "subclass_2.h"

            class TEST_INHERITANCE_BASIC : public SUBCLASS_1, SUBCLASS_2,QObject
            {
            Q_OBJECT
            public:
            TEST_INHERITANCE_BASIC();
            };

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on 7 Jan 2023, 17:59 last edited by
              #6

              ...and this is OK

              #include "subclass_1.h"
              #include "subclass_2.h"

              class TEST_INHERITANCE_BASIC : public SUBCLASS_1, SUBCLASS_2
              {
              //Q_OBJECT
              public:
              TEST_INHERITANCE_BASIC();
              };

              each SUBCLASS is derived from QObject

              C 1 Reply Last reply 7 Jan 2023, 18:07
              0
              • A Anonymous_Banned275
                7 Jan 2023, 17:59

                ...and this is OK

                #include "subclass_1.h"
                #include "subclass_2.h"

                class TEST_INHERITANCE_BASIC : public SUBCLASS_1, SUBCLASS_2
                {
                //Q_OBJECT
                public:
                TEST_INHERITANCE_BASIC();
                };

                each SUBCLASS is derived from QObject

                C Offline
                C Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on 7 Jan 2023, 18:07 last edited by
                #7

                @AnneRanch said in Define Class dialog (questions) ?:

                each SUBCLASS is derived from QObject

                You must not diamond derive from QObject

                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
                • C Offline
                  C Offline
                  Chris Kawa
                  Lifetime Qt Champion
                  wrote on 7 Jan 2023, 18:31 last edited by Chris Kawa 1 Jul 2023, 18:32
                  #8

                  When deriving from QObject moc assumes it's the first subclass on the inheritance list and, as Christian mentioned, only a single first class on the list can derive or be QObject, as documented here.

                  Also, when deriving from multiple classes make sure you put access specifier (e.g. public) in front of each class. It only applies to the directly following class name, not all on the list.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Anonymous_Banned275
                    wrote on 8 Jan 2023, 03:02 last edited by Anonymous_Banned275 1 Aug 2023, 03:10
                    #9

                    Thanks , I need to back paddle and revise my code .
                    I have way to many QObjects.... '

                    I went , as usual, little overboard and started with multiple inheritance ... bad idea...

                    I could use one more advise
                    I currently have a working "form" class and I am trying to make parts of the code as an independent reusable classes -hence my venture into inheritance,
                    '
                    Now if I desire to have one form, basically the "parent class " how do I pass the ui / widgets results from the subclass up to the main class ?
                    For example my subclass method contains several "DEBUG" messages . They need ti be posted in list widget, in sequence which is no issue when run in independent class.

                    Maybe I need to revisit "connect" ?
                    Can I do that "between subclass and main class": ?

                    A 1 Reply Last reply 8 Jan 2023, 16:09
                    0
                    • A Anonymous_Banned275
                      8 Jan 2023, 03:02

                      Thanks , I need to back paddle and revise my code .
                      I have way to many QObjects.... '

                      I went , as usual, little overboard and started with multiple inheritance ... bad idea...

                      I could use one more advise
                      I currently have a working "form" class and I am trying to make parts of the code as an independent reusable classes -hence my venture into inheritance,
                      '
                      Now if I desire to have one form, basically the "parent class " how do I pass the ui / widgets results from the subclass up to the main class ?
                      For example my subclass method contains several "DEBUG" messages . They need ti be posted in list widget, in sequence which is no issue when run in independent class.

                      Maybe I need to revisit "connect" ?
                      Can I do that "between subclass and main class": ?

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on 8 Jan 2023, 16:09 last edited by
                      #10

                      @AnneRanch

                      Here is an illustration what I am I talking about.

                      This is what the user should be interested in - the actual result of the process:

                      c260e84f-2f24-49ca-8330-1e6cdbf9c19a-image.png

                      this the tab I use while debugging my code

                      30a5cb1e-ee6e-4fde-9a48-902d0f7c0cc3-image.png

                      and this is what I a shooting for
                      on left a user window and on th right my, debugging window - for illustration only another instance of "Serial terminal"

                      76670e27-c93b-4f69-9f4f-53f336b3e5bf-image.png

                      This is definitely NOT KISS idea, but if it is feasible it would be a great exercise in C++ coding.

                      Any suggestions or opposing opinions are welcome.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        Anonymous_Banned275
                        wrote on 10 Jan 2023, 22:58 last edited by
                        #11

                        Related issue - I do not want to be accused of posting multiple times...

                        I have managed to create derived class , across two projects , the "include" code passes by compiler BUT
                        the linker (?) is complaining not to be able to find stuff.

                        /media/nov25-1/RAID_md125/JAN9/BT_JAN10_/CCC_SOURCE/BT_SPP_CA_CONNECT/bt_connect_master.cpp:-1: error: undefined reference to `DeviceDiscoveryDialog::DeviceDiscoveryDialog(QWidget*)'

                        Why? What am I missing ?

                        I did try to add another subclass ( QDialog) but it didn't work.

                        Here is how the subclass is defined

                        class DeviceDiscoveryDialog : public QDialog
                        {
                        Q_OBJECT

                        public:
                        DeviceDiscoveryDialog(QWidget *parent = nullptr);
                        ~DeviceDiscoveryDialog();

                        What is missing in my derived class definition ?

                        #include <QObject>
                        #include <QWidget>
                        // /media/nov25-1/RAID_md125/JAN9/BT_JAN10_/Qt-5.15.2/bluetooth/btscanner
                        // temporary full path 
                        #include "/media/nov25-1/RAID_md125/JAN9/BT_JAN10_/Qt-5.15.2/bluetooth/btscanner/device.h"
                        class BT_CONNECT_MASTER : public DeviceDiscoveryDialog
                        {
                            Q_OBJECT
                        public:
                            BT_CONNECT_MASTER();
                            QString text;
                        
                        };
                        1 Reply Last reply
                        0

                        1/11

                        7 Jan 2023, 16:46

                        • Login

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