Define Class dialog (questions) ?
-
- What is the purpose of the "entry box" under pull down "Base class " ?
- I there a way to add multiple inheritance ?
- Is there a way to actually add <Custom > , my own class, to inherit from ?
All while using "Define Class " dialog .

-
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;
^~~~~ -
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);
} -
When you use Q_OBJECT then yes, your class must derive from QObject somewhere in the inheritance tree - otherwise you get the errors above.
-
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();
}; -
...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
-
...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
@AnneRanch said in Define Class dialog (questions) ?:
each SUBCLASS is derived from QObject
You must not diamond derive from QObject
-
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. -
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": ? -
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": ?@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:

this the tab I use while debugging my code

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"
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.
-
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_OBJECTpublic:
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; };