QQuickView 和 QQuickWindow 有什么区别? [英] What's the difference between QQuickView and QQuickWindow?
问题描述
我目前正在使用 Qt 5.2.1... 我有一个(可能是愚蠢的?)问题:QQuickView
和 QQuickWindow
之间有什么区别?
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...
推荐答案
来自 Qt 文档:
QQuickView 类提供了一个显示 Qt Quick 用户的窗口界面.
The QQuickView class provides a window for displaying a Qt Quick user interface.
QQuickView 是 QQuickWindow 的一个方便的子类,它将给定 URL 时自动加载和显示 QML 场景主要源文件.
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.
所以 QQuickView 是 QQuickWindow 的子类,它管理从 QML 文件显示场景,并且可以轻松使用,例如:
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();
要在窗口中显示图形 QML 场景,您还可以使用 QQuickWindow 类.
For displaying a graphical QML scene in a window you can also use the QQuickWindow class.
同样来自 Qt 文档:
Also from the Qt documentation:
一个 QQuickWindow 总是有一个不可见的根项目.添加项目到此窗口,将项目重新设置为根项目或现有的场景中的项目.
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();
这篇关于QQuickView 和 QQuickWindow 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!