QML
维基百科,自由的百科全书
| QML | |
|---|---|
| 編程範型:宣告式編程、脚本语言 | |
|
发行时间
|
2009 |
|
實作者
|
Nokia |
| 最新发行时间 | 4.7.3[1] |
| dynamic typing、強型別 | |
|
啟發語言
|
JavaScript, Qt |
|
影響語言
|
Qt |
| For Developers | |
| 扩展名 | |
|---|---|
| 格式 | 脚本语言 |
QML (Qt Meta Language 或 Qt Modeling Language[2]) 是基於JavaScript、宣告式編程的程式語言,用於設計使用者介面為主的應用程式。它是Qt Quick,諾基亞開發的使用者介面建立套件的一部分。QML 主要用於行動應用程式,注重於觸控輸入、流暢的動畫(60張/秒)和使用者體驗。QML documents 描述元素的物件樹。
QML 元素可以透過標準 JavaScript 增強,包括這 inline 和引入.js 檔。元素可以也無縫整合和使用 Qt 框架的 C++ 元件擴展。
語言的名稱是 QML。runtime的名稱是 Qt Declarative。
目录 |
語法、語義 [编辑]
基本語法 [编辑]
範例:
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
開發工具 [编辑]
參考資料 [编辑]
- ^ Qt 4.7.3 Released. 4 May 2011 [2011-06-14].
- ^ Henrik Hartz (Product Manager for Qt Software at Nokia) comment on the name. 24 August 2009 [2011-06-14].