int qmlRegisterInterface ( const char * typeName )
This template function registers the C++ type in the QML system under the name typeName.
#include <QtDeclarative> to use this function.
Returns the QML type id.
int qmlRegisterType ( const char * uri, int versionMajor, int versionMinor, const char * qmlName )
This template function registers the C++ type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor.
Returns the QML type id.
There are two forms of this template function:
template<typename T>
int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
template<typename T, int metaObjectRevision>
int qmlRegisterType(const char *uri, int versionMajor, int versionMinor, const char *qmlName);
The former is the standard form which registers the type T as a new type. The latter allows a particular revision of a class to be registered in a specified version (see QML Type Versioning).
For example, this registers a C++ class MySliderItem as a QML type named Slider for version 1.0 of a module called "com.mycompany.qmlcomponents":
#include <QtDeclarative>
...
qmlRegisterType<MySliderItem>("com.mycompany.qmlcomponents", 1, 0, "Slider");
Once this is registered, the type can be used in QML by importing the specified module name and version number:
Note that it's perfectly reasonable for a library to register types to older versions than the actual version of the library. Indeed, it is normal for the new library to allow QML written to previous versions to continue to work, even if more advanced versions of some of its types are available.
int qmlRegisterType ()
This is an overloaded function.
This template function registers the C++ type in the QML system. Instances of this type cannot be created from the QML system.
#include <QtDeclarative> to use this function.
Returns the QML type id.
int qmlRegisterTypeNotAvailable ( const char * uri, int versionMajor, int versionMinor, const char * qmlName, const QString &message )
This function registers a type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajorand versionMinor, but any attempt to instantiate the type will produce the given error message.
Normally, the types exported by a module should be fixed. However, if a C++ type is not available, you should at least "reserve" the QML type name, and give the user of your module a meaningful error message.
Returns the QML type id.
Example:
#ifdef NO_GAMES_ALLOWED
qmlRegisterTypeNotAvailable("MinehuntCore", 0, 1, "Game", "Get back to work, slacker!");
#else
qmlRegisterType<MinehuntGame>("MinehuntCore", 0, 1, "Game");
#endif
This will cause any QML which uses this module and attempts to use the type to produce an error message:
fun.qml: Get back to work, slacker!
Game {
^
Without this, a generic "Game is not a type" message would be given.
#include <QtDeclarative> to use this function.
See also qmlRegisterUncreatableType().
int qmlRegisterUncreatableType ( const char * uri, int versionMajor, int versionMinor, const char * qmlName, const QString &message )
This template function registers the C++ type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor.
While the type has a name and a type, it cannot be created, and the given error message will result if creation is attempted.
This is useful where the type is only intended for providing attached properties or enum values.
Returns the QML type id.
#include <QtDeclarative> to use this function.