Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could I have copy constructor for subclass of QObject?

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?

like image 416
VALOD9 Avatar asked Sep 17 '14 12:09

VALOD9


People also ask

Is QObject Copyable?

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.

Which prototype can be copy constructor?

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);


1 Answers

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);
like image 59
Ezee Avatar answered Sep 21 '22 02:09

Ezee