I'm using QQmlApplicationEngine
as 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 QQmlApplicationEngine
doesn't seem to have a setFormat
method for enabling multisampling.
I found a way to do it with a QQmlApplicationEngine
in 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 QQmlApplicationEngine
and create a QQuickView
instead. This does have a setFormat
method letting me enable multisampling, but I'm wondering, am I losing anything by switching from QQmlApplicationEngine
to QQuickView
?
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?
QQuickWindow
, you only need aQWindow
. You can access it withapp.topLevelWindows().first()
after loading your qml file, no need to cast or get the root object. – Paragrapher