Qt-interest Archive, January 2007
Rationale behind disabling the Copying of QObjects
Message 1 in thread
What is the Rationale behind disabling the Copying of QObjects ?
For egs
QPushButton b ;
b.set[..];
QPushButton b2 = b; // is not allowed
I do know that this is not needed most of the times. but just wondering what
reason could be . Has it got anything to do with the pimpl implementation in
Qt ? or
Lets say
QObject *objButton = new QPushButton;
QObject *objLabel = new QLabel;
*objButton = *objLabel; // only the QObject parts gets copied
Are they trying to disable this kind of copying ?
Could someone shed some light into this topic ?
--
[ signature omitted ]
Message 2 in thread
Sunil Thaha schrieb:
> What is the Rationale behind disabling the Copying of QObjects ?
Perhaps because the objectName would be copied, too, which could cause
some friction?
Martin
--
[ signature omitted ]
Message 3 in thread
>> What is the Rationale behind disabling the Copying of QObjects ?
Perhaps this thread can give some hints about that subject, as copying
and serializing are somewhat related. Search for "copy-constructor".
http://lists.trolltech.com/qt-interest/2005-05/thread00963-0.html
Martin
--
[ signature omitted ]
Message 4 in thread
Sunil Thaha wrote:
> What is the Rationale behind disabling the Copying of QObjects ?
>
> For egs
> QPushButton b ;
> b.set[..];
>
> QPushButton b2 = b; // is not allowed
>
> I do know that this is not needed most of the times. but just wondering
> what reason could be . Has it got anything to do with the pimpl
> implementation in Qt ? or
>
> Lets say
>
> QObject *objButton = new QPushButton;
> QObject *objLabel = new QLabel;
>
> *objButton = *objLabel; // only the QObject parts gets copied
>
> Are they trying to disable this kind of copying ?
>
> Could someone shed some light into this topic ?
I think a big reason is the parent/child mechanism of Qt. I.e. deep copy
vs. shallow copy: do you copy the whole child hierarchy of a QObject or
not...
M
--
[ signature omitted ]
Message 5 in thread
On 31.01.07 17:57:44, Sunil Thaha wrote:
> What is the Rationale behind disabling the Copying of QObjects ?
As Martin already said, one part is the tree-of-childs that exists.
And for the official statement look into Trolltechs Knowledgebase:
http://www.trolltech.com/developer/knowledgebase/582/
Andreas
--
[ signature omitted ]
Message 6 in thread
> For egs
> QPushButton b ;
> b.set[..];
>
> QPushButton b2 = b; // is not allowed
>
> I do know that this is not needed most of the times. but just wondering
> what
> reason could be . Has it got anything to do with the pimpl implementation
> in
> Qt ? or
>
> Lets say
>
> QObject *objButton = new QPushButton;
> QObject *objLabel = new QLabel;
>
> *objButton = *objLabel; // only the QObject parts gets copied
>
> Are they trying to disable this kind of copying ?
>
> Could someone shed some light into this topic ?
Apart from what was correctly said here (should the object tree be copied?
what about signal/slot connections, event filter installations etc), the
most important reason is that in C++ you can devide all classes in two
types: value-types, and polymorph types. Value types have copy constructor
and assignment operators; polymorph types have a vitual table.
Creating a type that is both a value-type and a polymorph type is a bad
idea, as demonstrated by the following hypothetical example:
QPushButton pushButton;
QObject object = pushButton; // calls QObject's copy constructor or default
constructor + assignment operator
Q_ASSERT(object.metaObject()->indexOfSignal("clicked()") != -1);
This will assert. So "object" is not at all a copy of a QPushButton. It
would at best be an object that has the same properties as the pushbutton as
far as this is possible (the objectName in this trivial case).
Volker
--
[ signature omitted ]