QQmlEngineclass provides an environment for instantiating QML components. 更多 …
def
addImageProvider
(id, arg__2)
def
addImportPath
(dir)
def
addNamedBundle
(name, fileName)
def
addPluginPath
(dir)
def
baseUrl
()
def
clearComponentCache
()
def
imageProvider
(id)
def
importPathList
()
def
importPlugin
(filePath, uri, errors)
def
incubationController
()
def
networkAccessManager
()
def
networkAccessManagerFactory
()
def
offlineStorageDatabaseFilePath
(databaseName)
def
offlineStoragePath
()
def
pluginPathList
()
def
removeImageProvider
(id)
def
rootContext
()
def
setBaseUrl
(arg__1)
def
setImportPathList
(paths)
def
setIncubationController
(arg__1)
def
setNetworkAccessManagerFactory
(arg__1)
def
setOfflineStoragePath
(dir)
def
setOutputWarningsToStandardError
(arg__1)
def
setPluginPathList
(paths)
def
setUrlInterceptor
(urlInterceptor)
def
trimComponentCache
()
def
urlInterceptor
()
def
retranslate
()
def
contextForObject
(arg__1)
def
objectOwnership
(arg__1)
def
setContextForObject
(arg__1, arg__2)
def
setObjectOwnership
(arg__1, arg__2)
每个 QML 组件被实例化在
QQmlContext.QQmlContext‘s are essential for passing data to QML components. In QML, contexts are arranged hierarchically and this hierarchy is managed by theQQmlEngine.Prior to creating any QML components, an application must have created a
QQmlEngineto gain access to a QML context. The following example shows how to create a simple Text item.QQmlEngine engine; QQmlComponent component(&engine); component.setData("import QtQuick 2.0\nText { text: \"Hello world!\" }", QUrl()); QQuickItem *item = qobject_cast<QQuickItem *>(component.create()); //add item to view, etc ...In this case, the Text item will be created in the engine’s
root context.另请参阅
QQmlComponentQQmlContextQML 全局对象
QQmlEngine
(
[
p=None
]
)
¶
- param p
QObject
创建新的
QQmlEngine
采用给定
parent
.
PySide2.QtQml.QQmlEngine.
ObjectOwnership
¶
controls whether or not QML automatically destroys the
QObject
when the corresponding JavaScript object is garbage collected by the engine. The two ownership options are:
|
常量 |
描述 |
|---|---|
|
QQmlEngine.CppOwnership |
The object is owned by C++ code and QML will never delete it. The JavaScript destroy() method cannot be used on these objects. This option is similar to QScriptEngine::QtOwnership. |
|
QQmlEngine.JavaScriptOwnership |
The object is owned by JavaScript. When the object is returned to QML as the return value of a method call, QML will track it and delete it if there are no remaining JavaScript references to it and it has no
|
Generally an application doesn’t need to set an object’s ownership explicitly. QML uses a heuristic to set the default ownership. By default, an object that is created by QML has . The exception to this are the root objects created by calling
create()
or
beginCreate()
, which have by default. The ownership of these root-level objects is considered to have been transferred to the C++ caller.
Objects not-created by QML have by default. The exception to this are objects returned from C++ method calls; their ownership will be set to . This applies only to explicit invocations of
Q_INVOKABLE
methods or slots, but not to property getter invocations.
调用
setObjectOwnership()
overrides the default ownership heuristic used by QML.
PySide2.QtQml.QQmlEngine.
addImageProvider
(
id
,
arg__2
)
¶
id – unicode
arg__2
–
QQmlImageProviderBase
设置
provider
to use for images requested via the
image
: url scheme, with host
providerId
。
QQmlEngine
takes ownership of
provider
.
Image providers enable support for pixmap and threaded image requests. See the
QQuickImageProvider
documentation for details on implementing and using image providers.
All required image providers should be added to the engine before any QML sources files are loaded.
另请参阅
removeImageProvider()
QQuickImageProvider
QQmlImageProviderBase
PySide2.QtQml.QQmlEngine.
addImportPath
(
dir
)
¶
dir – unicode
添加
path
as a directory where the engine searches for installed modules in a URL-based directory structure.
path
may be a local filesystem directory, a
Qt Resource
path (
:/imports
),
Qt Resource
url (
qrc:/imports
) 或 URL。
path
will be converted into canonical form before it is added to the import path list.
The newly added
path
will be first in the
importPathList()
.
另请参阅
setImportPathList()
QML 模块
PySide2.QtQml.QQmlEngine.
addNamedBundle
(
name
,
fileName
)
¶
name – unicode
fileName – unicode
bool
PySide2.QtQml.QQmlEngine.
addPluginPath
(
dir
)
¶
dir – unicode
添加
path
as a directory where the engine searches for native plugins for imported modules (referenced in the
qmldir
file).
By default, the list contains only
.
, i.e. the engine searches in the directory of the
qmldir
file itself.
The newly added
path
will be first in the
pluginPathList()
.
另请参阅
PySide2.QtQml.QQmlEngine.
baseUrl
(
)
¶
QUrl
Return the base URL for this engine. The base URL is only used to resolve components when a relative URL is passed to the
QQmlComponent
构造函数。
If a base URL has not been explicitly set, this method returns the application’s current working directory.
另请参阅
PySide2.QtQml.QQmlEngine.
clearComponentCache
(
)
¶
Clears the engine’s internal component cache.
This function causes the property metadata of all components previously loaded by the engine to be destroyed. All previously loaded components and the property bindings for all extant objects created from those components will cease to function.
This function returns the engine to a state where it does not contain any loaded component data. This may be useful in order to reload a smaller subset of the previous component set, or to load a new version of a previously loaded component.
Once the component cache has been cleared, components must be loaded before any new objects can be created.
另请参阅
PySide2.QtQml.QQmlEngine.
contextForObject
(
arg__1
)
¶
arg__1
–
QObject
返回
QQmlContext
为
object
, or 0 if no context has been set.
当
QQmlEngine
instantiates a
QObject
, the context is set automatically.
另请参阅
setContextForObject()
qmlContext()
qmlEngine()
PySide2.QtQml.QQmlEngine.
exit
(
retCode
)
¶
retCode
–
int
PySide2.QtQml.QQmlEngine.
imageProvider
(
id
)
¶
id – unicode
QQmlImageProviderBase
Returns the image provider set for
providerId
if found; otherwise returns
None
.
另请参阅
PySide2.QtQml.QQmlEngine.
importPathList
(
)
¶
字符串列表
Returns the list of directories where the engine searches for installed modules in a URL-based directory structure.
例如,若
/opt/MyApp/lib/imports
is in the path, then QML that imports
com.mycompany.Feature
will cause the
QQmlEngine
to look in
/opt/MyApp/lib/imports/com/mycompany/Feature/
for the components provided by that module. A
qmldir
file is required for defining the type version mapping and possibly QML extensions plugins.
By default, the list contains the directory of the application executable, paths specified in the
QML2_IMPORT_PATH
environment variable, and the builtin
Qml2ImportsPath
from
QLibraryInfo
.
PySide2.QtQml.QQmlEngine.
importPlugin
(
filePath
,
uri
,
errors
)
¶
filePath – unicode
uri – unicode
errors
–
QList
bool
Imports the plugin named
filePath
采用
uri
provided. Returns true if the plugin was successfully imported; otherwise returns false.
On failure and if non-null, the
errors
list will have any errors which occurred prepended to it.
The plugin has to be a Qt plugin which implements the
QQmlEngineExtensionPlugin
接口。
PySide2.QtQml.QQmlEngine.
incubationController
(
)
¶
Returns the currently set incubation controller, or 0 if no controller has been set.
PySide2.QtQml.QQmlEngine.
networkAccessManager
(
)
¶
QNetworkAccessManager
Returns a common
QNetworkAccessManager
which can be used by any QML type instantiated by this engine.
若
QQmlNetworkAccessManagerFactory
has been set and a
QNetworkAccessManager
has not yet been created, the
QQmlNetworkAccessManagerFactory
will be used to create the
QNetworkAccessManager
; otherwise the returned
QNetworkAccessManager
will have no proxy or cache set.
PySide2.QtQml.QQmlEngine.
networkAccessManagerFactory
(
)
¶
PySide2.QtQml.QQmlEngine.
objectOwnership
(
arg__1
)
¶
arg__1
–
QObject
Returns the ownership of
object
.
另请参阅
PySide2.QtQml.QQmlEngine.
offlineStorageDatabaseFilePath
(
databaseName
)
¶
databaseName – unicode
unicode
Returns the file path where a
本地存储
database with the identifier
databaseName
is (or would be) located.
另请参阅
LocalStorage.openDatabaseSync()
PySide2.QtQml.QQmlEngine.
offlineStoragePath
(
)
¶
unicode
PySide2.QtQml.QQmlEngine.
outputWarningsToStandardError
(
)
¶
bool
Returns true if warning messages will be output to stderr in addition to being emitted by the
warnings()
signal, otherwise false.
默认值为 true。
PySide2.QtQml.QQmlEngine.
pluginPathList
(
)
¶
字符串列表
Returns the list of directories where the engine searches for native plugins for imported modules (referenced in the
qmldir
file).
By default, the list contains only
.
, i.e. the engine searches in the directory of the
qmldir
file itself.
PySide2.QtQml.QQmlEngine.
quit
(
)
¶
PySide2.QtQml.QQmlEngine.
removeImageProvider
(
id
)
¶
id – unicode
Removes the image provider for
providerId
.
PySide2.QtQml.QQmlEngine.
retranslate
(
)
¶
Refreshes all binding expressions that use strings marked for translation.
Call this function after you have installed a new translator with
installTranslator
, to ensure that your user-interface shows up-to-date translations.
注意
Due to a limitation in the implementation, this function refreshes all the engine’s bindings, not only those that use strings marked for translation. This may be optimized in a future release.
PySide2.QtQml.QQmlEngine.
rootContext
(
)
¶
Returns the engine’s root context.
The root context is automatically created by the
QQmlEngine
. Data that should be available to all QML component instances instantiated by the engine should be put in the root context.
Additional data that should only be available to a subset of component instances should be added to sub-contexts parented to the root context.
PySide2.QtQml.QQmlEngine.
setBaseUrl
(
arg__1
)
¶
arg__1
–
QUrl
Set the base URL for this engine to
url
.
另请参阅
PySide2.QtQml.QQmlEngine.
setContextForObject
(
arg__1
,
arg__2
)
¶
arg__1
–
QObject
arg__2
–
QQmlContext
设置
QQmlContext
为
object
to
context
。若
object
already has a context, a warning is output, but the context is not changed.
当
QQmlEngine
instantiates a
QObject
, the context is set automatically.
另请参阅
PySide2.QtQml.QQmlEngine.
setImportPathList
(
paths
)
¶
paths – 字符串列表
集
paths
as the list of directories where the engine searches for installed modules in a URL-based directory structure.
By default, the list contains the directory of the application executable, paths specified in the
QML2_IMPORT_PATH
environment variable, and the builtin
Qml2ImportsPath
from
QLibraryInfo
.
PySide2.QtQml.QQmlEngine.
setIncubationController
(
arg__1
)
¶
arg__1
–
QQmlIncubationController
Sets the engine’s incubation
controller
. The engine can only have one active controller and it does not take ownership of it.
PySide2.QtQml.QQmlEngine.
setNetworkAccessManagerFactory
(
arg__1
)
¶
arg__1
–
QQmlNetworkAccessManagerFactory
设置
factory
to use for creating
QNetworkAccessManager
(s).
QNetworkAccessManager
is used for all network access by QML. By implementing a factory it is possible to create custom
QNetworkAccessManager
with specialized caching, proxy and cookie support.
The factory must be set before executing the engine.
注意
QQmlEngine
does not take ownership of the factory.
PySide2.QtQml.QQmlEngine.
setObjectOwnership
(
arg__1
,
arg__2
)
¶
arg__1
–
QObject
arg__2
–
ObjectOwnership
设置
ownership
of
object
.
另请参阅
PySide2.QtQml.QQmlEngine.
setOfflineStoragePath
(
dir
)
¶
dir – unicode
另请参阅
PySide2.QtQml.QQmlEngine.
setOutputWarningsToStandardError
(
arg__1
)
¶
arg__1
–
bool
Set whether warning messages will be output to stderr to
enabled
.
若
enabled
is true, any warning messages generated by QML will be output to stderr and emitted by the
warnings()
信号。若
enabled
is false, only the
warnings()
signal will be emitted. This allows applications to handle warning output themselves.
默认值为 true。
PySide2.QtQml.QQmlEngine.
setPluginPathList
(
paths
)
¶
paths – 字符串列表
Sets the list of directories where the engine searches for native plugins for imported modules (referenced in the
qmldir
file) to
paths
.
By default, the list contains only
.
, i.e. the engine searches in the directory of the
qmldir
file itself.
PySide2.QtQml.QQmlEngine.
setUrlInterceptor
(
urlInterceptor
)
¶
urlInterceptor
–
QQmlAbstractUrlInterceptor
This API is private for 5.1
设置
urlInterceptor
to be used when resolving URLs in QML. This also applies to URLs used for loading script files and QML types. This should not be modifed while the engine is loading files, or URL selection may be inconsistent.
PySide2.QtQml.QQmlEngine.
trimComponentCache
(
)
¶
Trims the engine’s internal component cache.
This function causes the property metadata of any loaded components which are not currently in use to be destroyed.
A component is considered to be in use if there are any extant instances of the component itself, any instances of other components that use the component, or any objects instantiated by any of those components.
PySide2.QtQml.QQmlEngine.
urlInterceptor
(
)
¶
This API is private for 5.1
返回当前
QQmlAbstractUrlInterceptor
. It must not be modified outside the GUI thread.
PySide2.QtQml.QQmlEngine.
warnings
(
warnings
)
¶
warnings –