PDA

View Full Version : Do assignment operators in Qt4 return deep or shallow copy?



high_flyer
24th September 2006, 22:07
Well, the subject says it all...

Thanks.

jacek
24th September 2006, 22:14
Most objects in Qt implement copy-on-write mechanism. Which means that you get a shallow copy, which becomes a deep one as soon as you try to change it.

high_flyer
24th September 2006, 22:16
Which means that you get a shallow copy, which becomes a deep one as soon as you try to change it.
Could you explain that a bit more - or post a link to where this is to be found in the docs?
Thanks.

usern4me
24th September 2006, 22:32
http://doc.trolltech.com/4.2/shared.html

Brandybuck
24th September 2006, 23:47
In a nutshell, assignment operators in Qt are cheap. There's a lot of implicitly shared classes in Qt, and they're all cheap. Don't feel afraid to use them. Don't feel afraid to read the docs.

high_flyer
25th September 2006, 10:01
In a nutshell, assignment operators in Qt are cheap. There's a lot of implicitly shared classes in Qt, and they're all cheap.
Its not about it being cheap or not.
I knew that in Qt3 usually shallow copy was used.
It is important when you need to write your own copy constructors.
The key thing here is what jacek said about copy-on-write mechanism.
If this was not the case, I'd have to use explicit deep copy in my copy constructor.

Don't feel afraid to read the docs.
Does
or post a link to where this is to be found in the docs? tells you I am afraid of reading the docs? ;-)

@ user3me : thanks, I found it my self in the mean time.