QSObjectFactory Class Reference
The QSObjectFactory class provides a method for Qt Script
programs to create C++ QObjects.
More...
#include <qsobjectfactory.h>
Inherited by QSInputDialogFactory.
List of all member functions.
Public Members
virtual QStringList
classes () const
virtual QObject *
create ( const QString & className, const QSArgumentList & arguments, QObject * context )
virtual QObject *
createStatic ( const QString & className )
void registerClass ( const QString & className, QObject * staticInstance = 0 )
void registerClass ( const QString & className, const QString & cppClassName, QObject * staticInstance = 0 )
Protected Members
Detailed Description
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 classes() function is called by the scripting engine to see
which classes can be constructed by the script programmer. In
addition, the create() function is called by the scripting engine to create the
instance, i.e. when the user writes something like this:
var x = new SomeCppObject( arg1, arg2 ); // Qt Script
The staticClasses() function is called by the scripting engine
to check which classes provide static functions and variables.
A QObject instance is then created using createStatic()
to provide the interpreter of the static representation.
A single QSObjectFactory subclass may be used to provide any number of
creatable QObject classes. To make these classes known to the
scripting engine, create an instance of the subclass with a pointer
to the interpreter as an argument.
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.
Member Function Documentation
QSObjectFactory::QSObjectFactory ()
Constructor.
Creates the object factory. To make the object factory available to
an interpreter, use the function: QSInterpreter::addObjectFactory().
QStringList QSObjectFactory::classes () const [virtual]
This virtual function should be reimplemented in your
QSObjectFactory subclass when you want to instantiate objects from
script. It should return a list of the names of all the classes that
your QSObjectFactory is capable of instantiating.
This function is used by the scripting engine to find out which
classes this QSObjectFactory can instantiate.
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.
QObject * QSObjectFactory::createStatic ( const QString & className ) [virtual]
This virtual function should be reimplemented in your
QSObjectFactory subclass when you want to provide classes with
static contents. The class name is specified by className. Unlike
instances, static classes will always be located in the global
scope.
This function will return a QObject with slots and properties
that will be exposed to the interpreter as static variables and functions.
This function is called by the scripting engine during initialization
and can be used in code in the following way:
MessageBox.information( "This is a static function" );
The classes that a particular QSObjectFactory instance is capable of
providing static contents for is returned by staticClasses().
QSInterpreter * QSObjectFactory::interpreter () const [protected]
Returns the interpreter that this object factory is creating
objects for.
QStringList QSObjectFactory::staticClasses () const [virtual]
This virtual function should be reimplemented in your
QSObjectFactory subclass when you want to provide classes with
static contents. It should return a list of the names of all the
classes for which your QSObjectFactory will provide static contents.
This function is used by the scripting engine to find out which
classes this QSObjectFactory can instantiate.
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.