QQmlApplicationEngineprovides a convenient way to load an application from a single QML file. 更多 …
def
rootObjects
()
def
load
(filePath)
def
load
(url)
def
loadData
(data[, url=QUrl()])
def
setInitialProperties
(initialProperties)
def
objectCreated
(object, url)
此类结合
QQmlEngineandQQmlComponent提供加载单个 QML 文件的便捷方式。它还向 QML 暴露某些中心应用程序功能,C++/QML 混合应用程序通常从 C++ 进行控制。它可以像这样使用:
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine("main.qml"); return app.exec(); }不像
QQuickView,QQmlApplicationEnginedoes not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window .还可以使用
QCoreApplicationwithQQmlApplicationEngine, if you are not using any QML modules which require aQGuiApplication(譬如QtQuick).配置列表的改变从默认
QQmlEngine:
Translations are reloaded when the
QJSEngine::uiLanguage/Qt.uiLanguageproperty is changed.Automatically sets an incubation controller if the scene contains a
QQuickWindow.Automatically sets a
QQmlFileSelectoras the url interceptor, applying file selectors to all QML files and assets.The engine behavior can be further tweaked by using the inherited methods from
QQmlEngine.
QQmlApplicationEngine
(
[
parent=None
]
)
¶
QQmlApplicationEngine(filePath[, parent=None])
QQmlApplicationEngine(url[, parent=None])
- param parent
QObject- param url
QUrl- param filePath
unicode
创建新的
QQmlApplicationEngine
采用给定
parent
. You will have to call
load()
later in order to load a QML file.
PySide2.QtQml.QQmlApplicationEngine.
load
(
filePath
)
¶
filePath – unicode
PySide2.QtQml.QQmlApplicationEngine.
load
(
url
)
¶
url
–
QUrl
PySide2.QtQml.QQmlApplicationEngine.
loadData
(
data
[
,
url=QUrl()
]
)
¶
data
–
QByteArray
url
–
QUrl
Loads the QML given in
data
. The object tree defined by
data
is instantiated immediately.
若
url
is specified it is used as the base url of the component. This affects relative paths within the data and error messages.
If an error occurs, error messages are printed with
qWarning
.
PySide2.QtQml.QQmlApplicationEngine.
objectCreated
(
object
,
url
)
¶
object
–
QObject
url
–
QUrl
PySide2.QtQml.QQmlApplicationEngine.
rootObjects
(
)
¶
Returns a list of all the root objects instantiated by the
QQmlApplicationEngine
. This will only contain objects loaded via
load()
or a convenience constructor.
注意
In Qt versions prior to 5.9, this function is marked as non-
const
.
PySide2.QtQml.QQmlApplicationEngine.
setInitialProperties
(
initialProperties
)
¶
initialProperties –
设置
initialProperties
with which the QML component gets initialized after it gets loaded.