Results 1 to 3 of 3

Thread: Deep copy of widget hierarchy

  1. #1
    Join Date
    Jul 2009
    Posts
    8
    Thanks
    2

    Default Deep copy of widget hierarchy

    OK kind of long explanation here, bear with me please...

    I have a QWidget subclass, let's call it ScreenClass. After instantiating a ScreenClass, I may set a layout for it, and then add any number of child widgets (and possibly sub-layouts) to this "root" layout. These child widgets, in turn, may or may not have their own hierarchy of descendants. The descendant hierarchy of a ScreenClass instance is determined at runtime by interpreting information from a text file, so I have no idea ahead of time what exactly will be put in a ScreenClass instance.

    Here's my problem: I need to be able to make deep copies of any ScreenClass instance at runtime, duplicating its descendant hierarchy of widgets and layouts so that I have a complete and functional copy (except for signal connections, which I don't want to replicate right now). I have already written a copy constructor and overridden operator= for ScreenClass, and I have successfully made very rudimentary copies (right now just copying a couple of string properties), but I don't know how to take the next step of actually copying widgets and other complex objects. I've looked at QObject::children(), but I'm unsure how to make a deep copy of what it returns, or how it would be "applied" to the new copy.

    Are there any general principles or techniques for making deep copies of such unpredictable and complex object hierarchies? How do I start?

    Thanks for any help.
    Qt 4.5 2009.01 | Qwt 5.2.0 | MinGW 5.1.4 | Windows XP SP3

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Deep copy of widget hierarchy

    I dont think you can make copies of QWidget in Qt

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Deep copy of widget hierarchy

    It's possible to make such copies but only provided that you can reproduce the state of each widget based on the list of each properties or alternatively that you provide streaming operators for your widgets and do everything manually (you'll end up doing everything manually anyway). Out of the box widgets can't be copied, as already pointed out.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 08:06
  2. Copy full widget as a picture to clipboard
    By lasher in forum Newbie
    Replies: 1
    Last Post: 26th September 2009, 09:25
  3. QVector, containers, deep copy
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2007, 06:45
  4. Do assignment operators in Qt4 return deep or shallow copy?
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 10:01
  5. implicit or shared copy?
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2006, 15:14

Tags for this Thread

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.