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.
Maybe you are looking for the functionality provided by QUiLoader?
In general, you might want to look at these. As another poster pointed out, this functionality exists in Qt for (at least) Qt classes.
Generic factory in C++
Is there a way to instantiate objects from a string holding their class name?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With