Functions¶
Returns the QJSEngine
associated with object
, if any.
This function is useful if you have exposed a QObject to the JavaScript environment and later in your program would like to regain access. It does not require you to keep the wrapper around that was returned from newQObject()
.
- qmlClearTypeRegistrations()¶
- qmlProtectModule(uri, majVersion)¶
- Parameters:
uri – str
majVersion – int
- Return type:
bool
- qmlRegisterModule(uri, versionMajor, versionMinor)¶
- Parameters:
uri – str
versionMajor – int
versionMinor – int
- qmlRegisterSingletonType(url, uri, versionMajor, versionMinor, qmlName)¶
- Parameters:
url –
QUrl
uri – str
versionMajor – int
versionMinor – int
qmlName – str
- Return type:
int
- qmlRegisterType(url, uri, versionMajor, versionMinor, qmlName)¶
- Parameters:
url –
QUrl
uri – str
versionMajor – int
versionMinor – int
qmlName – str
- Return type:
int
- qmlRegisterUncreatableMetaObject(staticMetaObject, uri, versionMajor, versionMinor, qmlName, reason)¶
- Parameters:
staticMetaObject –
QMetaObject
uri – str
versionMajor – int
versionMinor – int
qmlName – str
reason – str
- Return type:
int
- qmlTypeId(uri, versionMajor, versionMinor, qmlName)¶
- Parameters:
uri – str
versionMajor – int
versionMinor – int
qmlName – str
- Return type:
int
- qmlAttachedPropertiesObject(type_obj, arg__2[, arg__3=true])¶
- qmlRegisterType(pytype: type, uri: str, versionMajor: int, versionMinor: int, qmlName: str) int ¶
- Parameters:
pytype (type) – Python class
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
qmlName (str) – name exposed to QML
- Returns:
int (the QML type id)
This function registers the Python type in the QML system with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor. For example, this registers a Python class ‘MySliderItem’ as a QML type named ‘Slider’ for version ‘1.0’ of a module called ‘com.mycompany.qmlcomponents’:
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:
import com.mycompany.qmlcomponents 1.0 Slider { ... }
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.
- qmlRegisterSingletonType(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str, callback: object) int ¶
- Parameters:
pytype (type) – Python class
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
typeName (str) – name exposed to QML
callback (object) – Python callable (to handle Python type)
- Returns:
int (the QML type id)
This function registers a Python type as a singleton in the QML system using the provided callback (which gets a QQmlEngine as a parameter) to generate the singleton.
- qmlRegisterSingletonType(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str) int ¶
- Parameters:
pytype (type) – Python class
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
typeName (str) – name exposed to QML
- Returns:
int (the QML type id)
This function registers a Python type as a singleton in the QML system.
Alternatively, the QmlSingleton decorator can be used.
- qmlRegisterSingletonType(uri: str, versionMajor: int, versionMinor: int, typeName: str, callback: object) int ¶
- Parameters:
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
typeName (str) – name exposed to QML
callback (object) – Python callable (to handle QJSValue)
- Returns:
int (the QML type id)
This function registers a QJSValue as a singleton in the QML system using the provided callback (which gets a QQmlEngine as a parameter) to generate the singleton.
- qmlRegisterSingletonInstance(pytype: type, uri: str, versionMajor: int, versionMinor: int, typeName: str, instanceObject: object) int ¶
- Parameters:
pytype (type) – Python class
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
typeName (str) – name exposed to QML
instanceObject (object) – singleton object to be registered
- Returns:
int (the QML type id)
This function registers a singleton Python object instanceObject, with a particular uri and typeName. Its version is a combination of versionMajor and versionMinor. Use this function to register an object of the given type pytype as a singleton type.
- qmlRegisterUncreatableType(pytype: type, uri: str, versionMajor: int, versionMinor: int, qmlName: str, noCreationReason: str) int ¶
- Parameters:
pytype (type) – Python class
uri (str) – uri to use while importing the component in QML
versionMajor (int) – major version
versionMinor (int) – minor version
qmlName (str) – name exposed to QML
noCreationReason (str) – Error message shown when trying to create the QML type
- Returns:
int (the QML type id)
This function registers the Python type in the QML system as an uncreatable type with the name qmlName, in the library imported from uri having the version number composed from versionMajor and versionMinor, showing noCreationReason as an error message when creating the type is attempted. For example, this registers a Python class ‘MySliderItem’ as a QML type named ‘Slider’ for version ‘1.0’ of a module called ‘com.mycompany.qmlcomponents’:
- ::
qmlRegisterUncreatableType(MySliderItem, “com.mycompany.qmlcomponents”, 1, 0, “Slider”, “Slider cannot be created.”)
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.
Alternatively, the QmlUncreatable decorator can be used.
Enumerations¶
- class QML_HAS_ATTACHED_PROPERTIES¶
- class QQmlModuleImportSpecialVersions¶