QML
QML (Qt Markup Language[2] 或 Qt Meta Language 或 Qt Modeling Language[3]) 是基于JavaScript、声明式编程的编程语言,用于设计图形用户接口为主的应用程序。它是Qt Quick,诺基亚开发的用户接口创建套件的一部分。QML 主要用于行动应用程序,注重于触摸输入、流畅的动画(60张/秒)和用户体验。QML documents 描述元素的对象树。
编程范型:声明式编程、脚本语言 | |
实作者 | Qt发展框架 |
2009 | |
当前版本 |
|
型态系统 | 动态、强类型 |
网站 | |
启发语言 | |
JavaScript、Qt | |
影响语言 | |
Qt |
.qml | |
text/x-qml | |
开发者 | Qt Project |
格式类型 | 脚本语言 |
网站 | qt-project |
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")
}
开发工具
由于 QML 和 Javascript 的语法相似,大多数支持 Javascript 的编辑器均可编辑 QML。但是从 Qt Creator 的 2.1 版本开始,该 IDE 提供了完整的语法高亮、代码补全、内建帮助和所见即所得编辑器。在商业版本的 Creator 中,所见即所得编辑器还会提供更多的功能。
参考数据
外部链接
This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.