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