[Qt-interest] Dynamically instantiate a class using the class name

Andre Somers andre at familiesomers.nl
Mon Jul 5 15:29:13 CEST 2010


On 5-7-2010 15:19, Mandeep Sandhu wrote:
> Hi All,
>
> Is there a way to programmatically  instantiate a class given it's name?
>
> Eg: I'm making a library which calls upon other helper classes to do
> the actual job. So a user calls a method say - setHelper(QString
> helpername) in this lib, and the lib internally instantiates an object
> of a class who's name is specified in "helpername". I'll have the
> "helper" classes follow a set interface so that my lib routines have a
> uniform way of interacting with all such helpers.
>
> Does the QT meta system provide such a feature?
>
> In java, Class.forName(String className) provides this functionality.
> Is there something similar in QT too?
>    
To me, it sounds like you are looking for the Factory pattern.

André

-- 
Nokia Certified Qt Developer.
Interested in Qt related job offers or freelance Qt consulting work.




More information about the Qt-interest-old mailing list