Eneboo - Documentación para desarrolladores
Métodos públicos | Métodos protegidos | Amigas
Referencia de la Clase QSObjectFactory

The QSObjectFactory class provides a method for Qt Script programs to create C++ QObjects. Más...

#include <qsobjectfactory.h>

Diagrama de herencias de QSObjectFactory
AQSObjectFactory FLObjectFactory QSInputDialogFactory QSUtilFactory

Lista de todos los miembros.

Métodos públicos

 QSObjectFactory ()
virtual ~QSObjectFactory ()
virtual QObjectcreate (const QString &className, const QSArgumentList &arguments, QObject *context)
void registerClass (const QString &className, QObject *staticInstance=0)
void registerClass (const QString &className, const QString &cppClassName, QObject *staticInstance=0)
QMap< QString, QObject * > staticDescriptors () const
QMap< QString, QStringinstanceDescriptors () const
void throwError (const QString &message)

Métodos protegidos

QSInterpreterinterpreter () const

Amigas

class QSInterpreter

Descripción detallada

The QSObjectFactory class provides a method for Qt Script programs to create C++ QObjects.

To enable script programmers to create their own C++ QObjects, application programmers can provide a QObject subclass that has a slot which is a factory function that returns QObjects. Alternatively, the application programmer can subclass QSObjectFactory and reimplement the create() and classes() functions.

The registerClass() function is called to register to the scripting engine each of the classes that this object factory can instantiate. In addition, the create() function is called by the scripting engine to create the instance, i.e. when the user writes something like

  var x = new SomeCppObject( arg1, arg2 ); // Qt Script

The function create() is reimplemented in each QSObjectFactory to provide the an instance of the QObject subclass that describes what the scripter should experience as an object of the type SomeCppObject.

A single QSObjectFactory subclass may be used to provide any number of creatable QObject classes. A QSObjectFactory becomes active when it is added to a QSInterpreter using the function QSInterpreter::addObjectFactory(). An object factory can only be added to one QSInterpreter at a time.


Documentación del constructor y destructor

QSObjectFactory::QSObjectFactory ( )

Constructor. Creates the object factory. To make the object factory available to an interpreter, use the function: QSInterpreter::addObjectFactory().

QSObjectFactory::~QSObjectFactory ( ) [virtual]

Documentación de las funciones miembro

QObject * QSObjectFactory::create ( const QString className,
const QSArgumentList arguments,
QObject context 
) [virtual]

This virtual function should be reimplemented in your QSObjectFactory subclass when you want to instantiate objects from script. The subclass can be used to create any number of different classes. The name of the required class is passed in the className argument, and the arguments to be passed to that class's constructor are passed in the arguments list. See QSArgument for further information about the arguments. context is the script QObject context in which the class has been instantiated, or 0 if the class has not been instantiated in a QObject context.

Only QObject subclasses may be created in this way. This function returns an instance of the requested class.

This function is called by the scripting engine, e.g. when it encounters code similar to the following:

    var x = new ACppObject( arg1, arg2 ); // Qt Script

The classes that a particular QSObjectFactory instance is capable of instantiating is returned by classes().

If the arguments are invalid or any other invalid operation happens, you can use throwError() to issue a Qt Script error.

All objects created from this function are deleted by the engine when the engine registers it as not being referenced anymore, unless the object at this time has a parent, which will then be responsible for ownership.

Reimplementado en AQSObjectFactory, FLObjectFactory, QSInputDialogFactory y QSUtilFactory.

QMap< QString, QString > QSObjectFactory::instanceDescriptors ( ) const
QSInterpreter * QSObjectFactory::interpreter ( ) const [protected]

Returns the interpreter that this object factory is creating objects for.

Reimplementado en QSUtilFactory.

void QSObjectFactory::registerClass ( const QString className,
QObject staticDescriptor = 0 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta.

void QSObjectFactory::registerClass ( const QString className,
const QString cppClassName,
QObject staticDescriptor = 0 
)

Registers that this object factory provides the class className.

This function is called once for each of the script classes that a subclass of QSObjectFactory wishes to expose to the scripting engine.

The name className is the name that the class has within the scripting engine. cppClassName is the name of the C++ class that is actually instantiated when className is passed to the create() function. For instance:

  // in script
  var x = new MyObject();

  // in C++
  QObject *create( const QString &name, ... ) {
      if( name == "MyObject" )
          return new MyScriptObject()
  }

Here we would call registerClass as follows:

  registerClass( "MyObject", "MyScriptObject" );

Providing QString::null in cppClassName will tell the interpreter that the class is not instantiable.

The staticDescriptor is used to describe the static part of a class. The properties, signals and slots of the staticDescriptor object will be accessible as className 's static part.

QMap< QString, QObject * > QSObjectFactory::staticDescriptors ( ) const
void QSObjectFactory::throwError ( const QString message)

Informs the interpreter that an error has occurred. The error is treated like a normal Qt Script error. The error message is passed in message.


Documentación de las funciones relacionadas y clases amigas

friend class QSInterpreter [friend]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'