問題描述
這里 我們可以讀到?jīng)]有復(fù)制構(gòu)造和復(fù)制賦值運(yùn)算符可評估.但是這里我們可以讀到qRegisterMetaType
和 Q_DECLARE_METATYPE
必須有公共默認(rèn)構(gòu)造函數(shù)、公共復(fù)制構(gòu)造函數(shù)和公共析構(gòu)函數(shù).問題是:誰在說謊?還是我沒有正確理解?
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?
推薦答案
一切都是真的:
1.QObject
不能被復(fù)制,它的所有后代也不能被復(fù)制.
2. Q_DECLARE_METATYPE
接受帶有公共構(gòu)造函數(shù)、復(fù)制構(gòu)造函數(shù)和析構(gòu)函數(shù)的對象.
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.
沒有矛盾,因?yàn)槟悴荒苡?code>Q_DECLARE_METATYPE注冊QObject
后代.
There is no contradiction, because you can't register QObject
descendants with Q_DECLARE_METATYPE
.
當(dāng)您將類轉(zhuǎn)換為 QVariant
時,它使用復(fù)制構(gòu)造函數(shù)來復(fù)制您的對象:
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);
這篇關(guān)于我可以為 QObject 的子類設(shè)置復(fù)制構(gòu)造函數(shù)嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!