我目前正在使用 Qt 5.2.1...并且我有一个(可能是愚蠢的?)问题:QQuickView
和 QQuickWindow
之间有什么区别?
我阅读了文档,但我仍然不清楚......
最佳答案
来自 Qt 文档:
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.
所以 QQuickView 是 QQuickWindow 的一个子类,它管理从 QML 文件中显示一个场景,并且可以像这样简单地使用:
QQuickView *view = new QQuickView;
view->setSource(QUrl::fromLocalFile("myqmlfile.qml"));
view->show();
为了在窗口中显示图形 QML 场景,您还可以使用 QQuickWindow 类。
同样来自 Qt 文档:
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.
所以它可以像这样使用:
QQmlApplicationEngine engine;
engine.load(QUrl("myqmlfile.qml"));
QObject *topLevel = engine.rootObjects().value(0);
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
window->show();
关于c++ - QQuickView 和 QQuickWindow 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23936169/