如何在Qt5和QML中使用QtQuick.Window元素?

如何在Qt5和QML中使用QtQuick.Window元素?,qt,window,qml,qt5,Qt,Window,Qml,Qt5,我最近安装了适用于Mac OS X的Qt5 RC2,并开始开发一些QML应用程序。在看了新元素之后,我特别想尝试一下窗口和屏幕元素。(http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html) 因此,我将导入设置在文件顶部,如下所示: 导入QtQuick 2.0 导入QtQuick.Window 2.0 找到导入,但我既不能使用窗口也不能使用屏幕。每次我输入屏幕或窗口时,都会出

我最近安装了适用于Mac OS X的Qt5 RC2,并开始开发一些QML应用程序。在看了新元素之后,我特别想尝试一下窗口和屏幕元素。(http://qt-project.org/doc/qt-5.0/qtquick/qmlmodule-qtquick-window2-qtquick-window-2.html)

因此,我将导入设置在文件顶部,如下所示:

导入QtQuick 2.0
导入QtQuick.Window 2.0

找到导入,但我既不能使用窗口也不能使用屏幕。每次我输入屏幕或窗口时,都会出现一个错误,上面写着“未知组件(M300)”


有人知道问题出在哪里吗?

有时QtCreator无法识别某些类型/属性,主要是Qt4.x中不存在的类型/属性,但这并不意味着您不能使用它们,所以是的,“窗口”是未知的,就像属性“抗锯齿”、“fontSizeMode”或“活动”一样,但您可以使用它们,以下是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"
            }
        }
    }
}

您只需要将一个窗口项作为根对象,就可以将其他窗口项嵌入其中。

Qt5.0就在这里。你试过那个吗?是的,我试过了。但它仍然不起作用。