Results 1 to 6 of 6

Thread: Do assignment operators in Qt4 return deep or shallow copy?

  1. #1
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Do assignment operators in Qt4 return deep or shallow copy?

    Well, the subject says it all...

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Do assignment operators in Qt4 return deep or shallow copy?

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Do assignment operators in Qt4 return deep or shallow copy?

    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.

  4. #4
    Join Date
    Sep 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Do assignment operators in Qt4 return deep or shallow copy?


  5. #5
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Do assignment operators in Qt4 return deep or shallow copy?

    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.

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Do assignment operators in Qt4 return deep or shallow copy?

    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.

Similar Threads

  1. implicit or shared copy?
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2006, 14:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.