在 QML 中,有以下基本类型:
int:整数类型。 Rectangle {function myFunction() {// 输出 debug 信息console.log("1+1 =" + (1+1));}Component.onCompleted: {myFunction();}}结果: 2. real:浮点类型。 3. double:双精度浮点类型。 4. string:字符串类型。
Rectangle {function myFunction() {// 输出 debug 信息console.log("helloworld");}Component.onCompleted: {myFunction();}}结果: 5. bool:布尔类型。 6. color:颜色类型,用于表示颜色的RGBA值。 7. var:通用类型,可以表示任意类型的数据。
Item {property var myVar: "Hello World"Component.onCompleted: {console.log(myVar) // 输出 "Hello World" 到控制台}}结果: 8. date:日期类型。
Rectangle {Item {property var currentDate: new Date()Component.onCompleted: {console.log(currentDate.toString()) // 输出当前日期和时间到控制台}}}结果: 9. point:点类型,用于表示二维空间中的点。
Item {width: 200height: 200property var point: Qt.point(50, 100)Component.onCompleted: {console.log(point.x, point.y) // 输出点对象的坐标值到控制台}}结果: 10. size:尺寸类型,用于表示宽度和高度。
Item {width: 200height: 200property size var_size: Qt.size(0, 2)Component.onCompleted: {console.log(var_size) // 输出点对象的坐标值到控制台}}结果: 11. rect:矩形类型,用于表示矩形区域的左上角坐标和宽高。
Item {width: 200height: 200property rect var_rect: Qt.rect(0, 0, 1, 2)Component.onCompleted: {console.log(var_rect) // 输出点对象的坐标值到控制台}}结果: