标题:qml中rectangle和window有什么区别
作者:qfmeal
日期:2015-11-25 10:12
内容:
代码如下:
import QtQuick 2.5
import QtQuick.Window 2.2
Rectangle
//Window
{
visible: true
width:360
height: 360
}上段代码使用qmlscene能正常显示窗口出来。
------------------------------------------------------------------------------------------------------------
但是使用qml创建的qt工程,加载这个qml文件不能显示出来,编译不报错
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/11.qml")));
return app.exec();
}------------------------------------------------------------------------------------------------------------
但是如果把qml中的Rectangle换成Window,那么qt工程和qmlscene就都可以正常显示了。
请问下这个Window和Rectangle有什么区别,或者说qmlscne和qt工程的调用方式有什么不同,谢谢。
#1 [tylan 11-25 15:32]
你应该使用的qml2.0及以上版本,在qml1.0或者1.1版本中是没有Window的,在2.0以后就有了。而且在1.0或者1.1版本中,使用qmlVIew而不是qmlScene来帮助显示qml文件。
#2 [qfmeal 11-26 09:50]
谢谢
#3 [ultramarine 09-11 10:22]
但是还是没有回答出二者的区别
#4 [toby520 09-12 12:15]
区别就去看帮助文档 对这2个组建的描述
1.Rectangle是继承Item 而Window -》QQuickWindow
2.The Window object creates a new top-level window for a Qt Quick scene. It automatically sets up the window for use with QtQuick 2.x graphical types. 是个顶级窗口 Rectangle不是