Here we can read that no copy construct and copy assignment operator evaluable. But here we can read that qRegisterMetaType
and Q_DECLARE_METATYPE
have to have public default constructor, public copy constructor and public destructor. The question is: who is telling a lie? Or I did not understand it correctly?
There are several reasons why a QObject can't be copied. The two biggest reasons are: QObjects usually communicate with each other using the signals and slots mechanism. It's unclear whether the connected signals and/or slots should be transferred over to the copy.
Copy Constructor in C++ A copy constructor is a member function that initializes an object using another object of the same class. A copy constructor has the following general function prototype: ClassName (const ClassName &old_obj);
Everything is true:
1. QObject
can't be copied and all its descendants can't be copied also.
2. Q_DECLARE_METATYPE
accepts objects with public constructor, copy constructor and destructor.
There is no contradiction, because you can't register QObject
descendants with Q_DECLARE_METATYPE
.
EDIT:
When you convert your class to QVariant
it uses a copy constructor to make a copy of your object:
void *ptr = QMetaType::construct(x->type, copy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With