What's the difference between QQuickView and QQuickWindow?

旧街凉风 提交于 2020-04-09 05:18:53

问题


I am currently working with Qt 5.2.1... and I have a (maybe stupid?) question: What is the difference between QQuickView and QQuickWindow?

I read the documentation but it is still not clear to me...


回答1:


From the Qt documentation:

The QQuickView class provides a window for displaying a Qt Quick user interface.

QQuickView is a convenience subclass of QQuickWindow which will automatically load and display a QML scene when given the URL of the main source file.

So QQuickView is a subclass of QQuickWindow which manages displaying a scene from a QML file and could be used easily like:

QQuickView *view = new QQuickView;
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();

For displaying a graphical QML scene in a window you can also use the QQuickWindow class.

Also from the Qt documentation:

A QQuickWindow always has a single invisible root item. To add items to this window, reparent the items to the root item or to an existing item in the scene.

So it can be used like:

QQmlApplicationEngine engine;
engine.load(QUrl("myqmlfile.qml"));

QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);

window->show();


来源:https://stackoverflow.com/questions/23936169/whats-the-difference-between-qquickview-and-qquickwindow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!