tags:

views:

89

answers:

2

Can I create an object of a class at runtime, by extracting the class name stored in a string?

eg: I want to create and object of class QButton like

QString strClassName = "QButton";
QButton *pBtn = new strClassName();

I want to read an xml file of all the controls and instantiate them at runtime using this way.

Thanks!

+6  A: 

Maybe you are looking for the functionality provided by QUiLoader (http://doc.trolltech.com/4.6/quiloader.html)?

Greg S
this simply roxxx0r.
Alexandre C.
Well, I started falling in love with Qt.. :D
liaK
+2  A: 

In general, you might want to look at these. As another poster pointed out, this functionality exists in Qt for (at least) Qt classes.

http://stackoverflow.com/questions/1741178/generic-factory-in-c

http://stackoverflow.com/questions/582331/c-is-there-a-way-to-instantiate-objects-from-a-string-holdig-their-class-name

Nubsis