我最近为 Mac OS X 安装了 Qt5 RC2 并开始开发一些 QML 应用程序。看了新元素后,特别想试试Window和Screen Element。(http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html)
所以我将导入设置在文件的顶部,如下所示:
导入 QtQuick 2.0
导入 QtQuick.Window 2.0
找到了导入,但我既不能使用 Window 也不能使用 Screen。每次我输入 Screen 或 Window 都会出现一个错误,上面写着“未知组件 (M300)”
有谁知道问题是什么?
有时 QtCreator 无法识别某些类型/属性,主要是 Qt4.x 中不存在的类型/属性,但这并不意味着您不能使用它们,所以是的,“Window”就像属性“antialiasing”一样是未知的, 'fontSizeMode' 或 'active' 是,但您可以使用它们,这是 QtQuick.Window 2.0 的使用示例:
import QtQuick 2.0
import QtQuick.Window 2.0
Window {
id: win1;
width: 320;
height: 240;
visible: true;
color: "yellow";
title: "First Window";
Text {
anchors.centerIn: parent;
text: "First Window";
Text {
id: statusText;
text: "second window is " + (win2.visible ? "visible" : "invisible");
anchors.top: parent.bottom;
anchors.horizontalCenter: parent.horizontalCenter;
}
}
MouseArea {
anchors.fill: parent;
onClicked: { win2.visible = !win2.visible; }
}
Window {
id: win2;
width: win1.width;
height: win1.height;
x: win1.x + win1.width;
y: win1.y;
color: "green";
title: "Second Window";
Rectangle {
anchors.fill: parent
anchors.margins: 10
Text {
anchors.centerIn: parent
text: "Second Window"
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
您只需要有一个 Window 项作为根对象,您就可以将其他 Window 项嵌入其中。