Define Class dialog (questions) ?
-
wrote on 7 Jan 2023, 16:46 last edited by
-
wrote on 7 Jan 2023, 16:56 last edited by
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;
^~~~~ -
wrote on 7 Jan 2023, 17:20 last edited by
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);
} -
Lifetime Qt Championwrote on 7 Jan 2023, 17:44 last edited by Christian Ehrlicher 1 Jul 2023, 17:44
When you use Q_OBJECT then yes, your class must derive from QObject somewhere in the inheritance tree - otherwise you get the errors above.
-
wrote on 7 Jan 2023, 17:53 last edited by
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();
}; -
wrote on 7 Jan 2023, 17:59 last edited by
...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
-
Lifetime Qt Championwrote on 7 Jan 2023, 18:31 last edited by Chris Kawa 1 Jul 2023, 18:32
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. -
wrote on 8 Jan 2023, 03:02 last edited by Anonymous_Banned275 1 Aug 2023, 03:10
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": ?wrote on 8 Jan 2023, 16:09 last edited by@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.
-
wrote on 10 Jan 2023, 22:58 last edited by
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; };
1/11