QML
外观
	
	

|  | 此條目包含指南或教學內容。 (2016年5月25日) | 
|  | 此条目形似評論,須要清理。 (2016年5月25日) | 
| 编程范型 | 編程範型:宣告式編程、脚本语言 | 
|---|---|
| 實作者 | Qt發展框架 | 
| 发行时间 | 2009 | 
| 当前版本 | 
 | 
| 型態系統 | 動態、強型別 | 
| 網站 | [1] | 
| 受影响于 | |
| JavaScript、Qt | |
| 影響語言 | |
| Qt | |
| 扩展名 | 
.qml | 
|---|---|
| 互联网媒体类型 | text/x-qml | 
| 开发者 | Qt Project | 
| 格式类型 | 脚本语言 | 
| 网站 | qt-project | 
QML (Qt Markup Language[3] 或 Qt Meta Language 或 Qt Modeling Language[4]) 是基於JavaScript、宣告式編程的程式語言,用於設計圖形使用者介面為主的應用程式。它是Qt Quick,諾基亞開發的使用者介面建立套件的一部分。QML 主要用於行動應用程式,注重於觸控輸入、流暢的動畫(60張/秒)和使用者體驗。QML documents 描述元素的物件樹。
QML 元素可以透過標準 JavaScript 增強,包括這 inline 和引入.js 檔。元素可以也無縫整合和使用 Qt 框架的 C++ 元件擴展。
語言的名稱是 QML。runtime的名稱是 QQuickView。
語法、語義
[编辑]基本語法
[编辑]範例:
import QtQuick 1.0
 Rectangle {
     id: canvas
     width: 200
     height: 200
     color: "blue"
     Image {
         id: logo
         source: "pics/logo.png"
         anchors.centerIn: parent
         x: canvas.height / 5      
     }
 }
動畫
[编辑] Rectangle {
     id: rect
     width: 120; height: 200
     Image {
         id: img
         source: "pics/qt.png"
         x: 60 - img.width/2
         y: 0
         SequentialAnimation on y {
             loops: Animation.Infinite
             NumberAnimation { to: 200 - img.height; easing.type: Easing.OutBounce; duration: 2000 }
             PauseAnimation { duration: 1000 }
             NumberAnimation { to: 0; easing.type: Easing.OutQuad; duration: 1000 }
         }
     }
 }
Qt/C++ 整合
[编辑]QML 不需要 Qt/C++ 的知識就能使用,但它可以輕鬆地擴展 Qt。
熟悉的概念
QML 提供直接訪問,從以下來自 Qt 的概念:
- QAction – action 類型
- QObject signals and slots – 作為在 JavaScript 中調用的函數
- QObject properties – 作為 JavaScript 中的變數
- QWidget – QDeclarativeView 是一個 QML-displaying widget
- Q*Model – 直接用在資料綁定 (如 QAbstractItemModel)
Qt 信號處理式
[编辑] MouseArea {
     onPressed: console.log("mouse button pressed")
 }
操作方法
[编辑]- Calling Qt class methods from QML
- Creating a custom QML element with Qt
- Connecting Qt signal to QML function
開發工具
[编辑]由于 QML 和 Javascript 的语法相似,大多数支持 Javascript 的编辑器均可编辑 QML。但是从 Qt Creator 的 2.1 版本开始,该 IDE 提供了完整的语法高亮、代码补全、内建帮助和所见即所得编辑器。在商业版本的 Creator 中,所见即所得编辑器还会提供更多的功能。
參考資料
[编辑]- ^ Qt 6.4 Released. 2022年9月29日.
- ^ Qt 5.14.1 Released. 2020-01-27 [2020-03-10]. (原始内容存档于2020-04-08).
- ^ Qt 4.8: QML Tutorial. [2013-10-31]. (原始内容存档于2013-11-02).
- ^ Henrik Hartz (Product Manager for Qt Software at Nokia) comment on the name. 24 August 2009 [2011-06-14]. (原始内容存档于2011-07-23).
 
	
