2012-12-20 25 views
3

我最近安裝了適用於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)如何在Qt5和QML中使用QtQuick.Window元素?

所以我設定的進口在這樣的文件的頂部:

進口QtQuick 2.0
進口QtQuick.Window 2.0

進口被發現,但我可以既不使用也不窗口畫面。每當我鍵入屏幕或窗口時出現一個錯誤,說「未知組件(M300)」

有沒有人知道問題是什麼?

+0

Qt 5.0在那裏。那個試過了嗎? – sebasgo

+0

是的,我試過了。但它仍然不起作用。 – Dominik

回答

3

有時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" 
      } 
     } 
    } 
} 

你只需要有一個窗口項目的根對象,並且可以嵌入其他窗口項目。