2016-12-09 68 views
0

如何爲login.qml文件生成.cpp和.h文件?從qt創建器中的..qml文件生成.cpp和.h文件

我爲登錄頁面編寫了一個.qml文件。

我的代碼如下

進口QtQuick 1.0

Rectangle{ 
    id:screen 
    color: "lightgray" 
    width: 3000; height:2700 

    Column { 
     id: column1 
     width: 201 
     height: 400 

     Row { 
      id: row1 
      width: 40 
      height:50 

      TextInput { 
       id: userName 
       x: 40 
       y: 18 
       width: 80 
       height: 20 
       text: qsTr("UserName") 
       font.pixelSize: 12 
      } 

      Rectangle { 
       id: rectangle1 
       x: 115 
       y: 18 
       width: 80 
       height: 20 
       color: "#ffffff" 
      } 


     } 

     Row { 
      id: row2 
      width: 40 
      height: 50 

      TextInput { 
       id: password 
       x: 40 
       y: 18 
       width: 80 
       height: 20 
       text: qsTr("Password") 
       font.pixelSize: 12 
      } 

      Rectangle { 
       id: rectangle2 
       x: 115 
       y: 18 
       width: 80 
       height: 20 
       color: "#ffffff" 
      } 
     } 

     Row { 
      id: row3 
      x: 8 
      y: 113 
      width: 40 
      height: 50 

      Rectangle { 
       id: rectangle3 
       x: 8 
       y: 8 
       width: 80 
       height: 20 
       color: "#ffffff" 

      Text { 
        id: login 
        text: "Login" 
        x:4 
        y:4 
        width:30 
        height:10 
        font.pixelSize: 12 
       } 

        } 

     } 



    } 

    MouseArea { 
      anchors.fill: parent 
      onClicked: { 
       myclass.doStuffFromQmlSlot(); 

       Qt.quit(); 
      } 
     } 

} 
+0

'import QtQuick 1.0' - > Qt和Qt Creator的版本是什麼? QtQuick 1在Qt 5中已棄用.Qt Creator中可能有一個「Qt Quick Application」項目模板(至少有更新的版本,不確定較舊的版本),只需創建一個並替換那裏的QML(可能會改變main.cpp來加載你的文件),那麼你可以爲你的代碼構建一個真正的可執行文件。 – E4z9

+2

你爲什麼想這樣做? 在Qt企業版中有一個Qt Quick Compiler,可以將qml文件透明地編譯爲C++。 – GrecKo

回答

0

那將是相當一些工作。

您需要編寫一個C++代碼生成器或找到一個現有的代碼生成器。

您需要解析QML代碼或加載它並遍歷樹來提供代碼生成器。

然後,您生成的代碼將依賴於私有Qt頭文件,或者您需要您自己的QtQuick類型實現。