Contents
Public Functions
Public Slots
Signals
Detailed Description
QQmlApplicationEngine Class
QQmlApplicationEngine provides a convenient way to load an application from a single QML file. More…
Header:
include
qmake:
QT += qml
Since:
Qt 5.1
Inherits:
QQmlEngine
List of all members, including inherited members
Public Functions
QQmlApplicationEngine(QObject *parent = 0)
QQmlApplicationEngine(const QUrl &url, QObject *parent = 0)
QQmlApplicationEngine(const QString &filePath, QObject *parent = 0)
~QQmlApplicationEngine()
QList
include
#include
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine(“main.qml”);
return app.exec();
}
Unlike QQuickView, QQmlApplicationEngine does 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. !!如何放在一个窗口中,用什么容器控件!?
You can also use QCoreApplication with QQmlApplicationEngine, if you are not using any QML modules which require a QGuiApplication (such as QtQuick).
List of configuration changes from a default QQmlEngine:
Connecting Qt.quit() to QCoreApplication::quit()
Automatically loads translation files from an i18n directory adjacent to the main QML file.
Automatically sets an incubation controller if the scene contains a QQuickWindow.
Automatically sets a QQmlFileSelector as 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.
Member Function Documentation
QQmlApplicationEngine::QQmlApplicationEngine(QObject *parent = 0)
Create a new QQmlApplicationEngine with the given parent. You will have to call load() later in order to load a QML file.
在构造函数中传入QML file
QQmlApplicationEngine::QQmlApplicationEngine(const QUrl &url, QObject *parent = 0)
Create a new QQmlApplicationEngine and loads the QML file at the given url. This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.
QQmlApplicationEngine::QQmlApplicationEngine(const QString &filePath, QObject *parent = 0)
Create a new QQmlApplicationEngine and loads the QML file at the given filePath, which must be a local file path. If a relative path is given then it will be interpreted as relative to the working directory of the application.
This is provided as a convenience, and is the same as using the empty constructor and calling load afterwards.
QQmlApplicationEngine::~QQmlApplicationEngine()
Destroys the QQmlApplicationEngine and all QML objects it loaded.
加载QML file
[slot] void QQmlApplicationEngine::load(const QUrl &url)
Loads the root QML file located at url. The object tree defined by the file is created immediately for local file urls. Remote urls are loaded asynchronously, listen to the objectCreated signal to determine when the object tree is ready.
If an error occurs, error messages are printed with qWarning.
加载QML file文件路径
[slot] void QQmlApplicationEngine::load(const QString &filePath)
Loads the root QML file located at filePath. filePath must be a path to a local file. If filePath is a relative path, it is taken as relative to the application’s working directory. The object tree defined by the file is instantiated immediately.
If an error occurs, error messages are printed with qWarning.
[slot] void QQmlApplicationEngine::loadData(const QByteArray &data, const QUrl &url = QUrl())
Loads the QML given in data. The object tree defined by data is instantiated immediately.
If a 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.
[signal] void QQmlApplicationEngine::objectCreated(QObject *object, const QUrl &url)
This signal is emitted when an object finishes loading. 当对象加载完成,传出这个信号If loading was successful, object contains a pointer to the loaded object传回加载对象的指针. Otherwise the pointer is NULL. The url loaded is also provided, note that if a QString file path was initially passed to the QQmlApplicationEngine, this url will be the equivalent of QUrl::fromLocalFile(filePath).
QList