What is the difference between QQmlApplicationEngine and QQuickView?

Headline: QQmlApplicationEngine is newer and more powerful than QQuickView.

QQmlApplicationEngine exposes some central application functionality to QML, which QQuickView application would normally control from C++:

  • 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.

Ref: Qt docs

At the time when QQmlApplicationEngine was introduced, the Qt Blog had this to say:

In Qt 5.0 we generally created Qt Quick applications by declaring a QQuickView in C++ and setting the base url on it. The drawback of that approach is that you have to use C++ to set properties like width, height etc. In Qt 5.1 we encourage using Window or ApplicationWindow as the root item of your application, giving complete control to Qt Quick, so we are now introducing the QQmlApplicationEngine to make this use case a little bit simpler. The QmlApplicationEngine is all you need to set up your qt quick window, pick up the right translation files and it implicitly connects the application quit() signal to your root window.

Qt Quick Controls 2.0 is able to make use of this extra application control, through the new item ApplicationWindow, which:

  • is similar to the regular QQuickWindow, but adds support for setting a window specific MenuBar, ToolBar and StatusBar in QML.
  • makes it convenient to add a header and footer item to the window.
  • makes it possible to control the window's properties, appearance and layout from QML.
  • supports popups via its overlay property, which ensures that popups are displayed above other content and that the background is dimmed when a modal popup is visible.

So, in order to use some of the Qt Quick Controls features like MenuBar and Popup, we need to:

  • use ApplicationWindow as our top-level QML item instead of Rectangle or Item
  • use the new QQmlApplicationEngine to load the QML from C++ instead of the old QQuickView.

You can use both together if you don't want your top level item to be a Window.

QQmlApplicationEngine engine;
QQuickView view(&engine, 0);
// your usual engine code
view.show();