What is the difference between QQmlApplicationEngine and QQuickView?
-
I'm using
QQmlApplicationEngineas follows:QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); app.exec();But now I want to enable multisampling for my app, and
QQmlApplicationEnginedoesn't seem to have asetFormatmethod for enabling multisampling.I found a way to do it with a
QQmlApplicationEnginein a forum:QQuickWindow* window = (QQuickWindow*) engine.rootObjects().first(); QSurfaceFormat format; format.setSamples(16); window->setFormat(format)But it relies on the first root object of the engine being a
QQuickWindow, which is not documented in Qt docs. So I don't want to use that technique.Another way would be to skip
QQmlApplicationEngineand create aQQuickViewinstead. This does have asetFormatmethod letting me enable multisampling, but I'm wondering, am I losing anything by switching fromQQmlApplicationEnginetoQQuickView?In other words, what are the differences between these two classes?
One difference I found is this (from here):
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.
This particular difference doesn't matter to me.
Any other differences?
-
@Stefan-Monov76
The basic difference isQQmlApplicationEnginecan only load QML files which have root component asWindoworApplicationWindowwhileQQuickViewloads any QML type which inheritsItem.But it relies on the first root object of the engine being a QQuickWindow, which is not documented in Qt docs. So I don't want to use that technique.
If you use
QQmlApplicationEngineyou have to useWindoworApplicationWindowwhich instantiatesQQuickWindow.
So AFAIK the code you posted is the only way to set the samples. -
@Stefan-Monov76
The basic difference isQQmlApplicationEnginecan only load QML files which have root component asWindoworApplicationWindowwhileQQuickViewloads any QML type which inheritsItem.But it relies on the first root object of the engine being a QQuickWindow, which is not documented in Qt docs. So I don't want to use that technique.
If you use
QQmlApplicationEngineyou have to useWindoworApplicationWindowwhich instantiatesQQuickWindow.
So AFAIK the code you posted is the only way to set the samples.@p3c0 : Thanks. Seems like someone had too much time on their hands and spent it creating redundant classes :)
-
@Stefan-Monov76 As the docs say
QQuickViewis convenience subclass ofQQuickWindow. -
QQmlApplicationEngineis a convenience class introduced in Qt 5.1, with several advantages overQQuickView:- Can also be used for non-graphical purposes (so whether the root object is a
QQuickViewdepends on the QML you're loading). - Automates a bunch of things (
Qt.quit(), translations, file selectors) - Allows subclasses like
ApplicationWindowto be used as root item (whereas you would have aWindownested in aWindowwhen using aQQuickView, I'm not sure what it does in that case)
While technically redundant, I think it was a welcome addition since it saves a lot of boilerplate code.
- Can also be used for non-graphical purposes (so whether the root object is a
-
QQmlApplicationEngineis a convenience class introduced in Qt 5.1, with several advantages overQQuickView:- Can also be used for non-graphical purposes (so whether the root object is a
QQuickViewdepends on the QML you're loading). - Automates a bunch of things (
Qt.quit(), translations, file selectors) - Allows subclasses like
ApplicationWindowto be used as root item (whereas you would have aWindownested in aWindowwhen using aQQuickView, I'm not sure what it does in that case)
While technically redundant, I think it was a welcome addition since it saves a lot of boilerplate code.
@thorbjorn : Thanks! Very useful answer (unlike the docs, which are really lacking on this :) ). I'll use the
QQmlApplicationEngineway. - Can also be used for non-graphical purposes (so whether the root object is a