oopapidocs  2.0
objectfactory.cpp
00001 #include <QDebug>
00002 #include <QObject>
00003 #include <QApplication>
00004 #include <QMetaObject>
00005 
00006 #include "objectfactory.h"
00007 #include "address.h"
00008 #include "country.h"
00009 
00010 //start id=newobject
00011 ObjectFactory::ObjectFactory() {
00012     m_knownClasses["UsAddress"] = UsAddress::staticMetaObject;
00013     m_knownClasses["CanadaAddress"] = CanadaAddress::staticMetaObject;
00014 }
00015 
00016 QObject* ObjectFactory::newObject(QString className, QObject* parent) {
00017     QObject* retval = 0;
00018     if (m_knownClasses.contains(className)) {
00019         const QMetaObject& mo = m_knownClasses[className];
00020         retval = mo.newInstance();      /* Requires Qt 4.5 or later. */
00021         if (retval == 0) {
00022             qDebug() << "Error creating " << className;
00023             abort();
00024         }
00025     } else {
00026         qDebug() << QString("Generic QObject created for new %1")
00027                     .arg(className);
00028         retval = new QObject();
00029         retval->setProperty("className", className);
00030     }
00031     if (parent != 0) retval->setParent(parent);
00032     return retval;
00033 }
00034 //end
00035 
00036 
 All Classes Namespaces Functions Enumerations