This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QObject> | |
#include <QDebug> | |
class FactoryBase | |
{ | |
public: | |
virtual QObject* create() = 0; | |
}; | |
QMap<QString, FactoryBase*> factoryMap; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://kunalmaemo.blogspot.com/2010/07/creating-class-dynamically-from-its.html | |
Some time it could be useful to be able to create new instance of class just by knowing its name. Such as in situation like when you are receiving XML from network and you want to create certain type of parser depending upon XML received from network. | |
In Qt its possible by using Qt's meta object system. | |
Here is my sample implementation that uses QMetaType to achieve the same. In sample code Parser is base class of all parser. | |
class Parser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
http://bbs.csdn.net/topics/340251573?page=2 | |
http://bbs.csdn.net/topics/390480286 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <string> | |
#include <iostream> | |
namespace MyNameSpace { | |
class Base | |
{ | |
public: | |
virtual char* GetName() const = 0; | |
}; |
OlderNewer