PDA

View Full Version : create a Object by its name.



weixj2003ld
10th August 2011, 03:18
I have define many class,and their names are like this:
Icon1,Icon2,Icon3,....,Icon1000;

Now I want to know that how to create an object of them dynamicly by the digital in their names?
For example,If I know 6,how I create the object of Icon6?

Santosh Reddy
10th August 2011, 04:55
First thing if you are creating 1000 classes of Icon (like Icon1, Icon2....) then you should be doing something which is way out of the way. Rather you should be creating hierarchy of classes and objects of them.

Second, the only option to create the object (IMO), with just knowing the digit in the class name is to create a switch statement with 1000 cases. I am sure no-body would like to write such thing, unless code automatically generated.

wysota
10th August 2011, 09:43
If those classes inherited QObject, they could be marshalled by name.