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.
Bookmarks