QML笔记-QML基本数据类型的使用
生活随笔
收集整理的這篇文章主要介紹了
QML笔记-QML基本数据类型的使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
目錄
?
基本概念
舉個栗子
?
基本概念
這里的數據類型不僅僅有C++里面的int,String等,
還有個很有特點的類型var,這個又可以放數組,也可以放函數,也可以混著換,很少有趣。
?
舉個栗子
程序運行截圖如下:
后臺打印如下:
?
?
源碼如下:
import QtQuick 2.9 import QtQuick.Window 2.2Window {visible: truewidth: 640height: 480title: qsTr("Hello World")property string mString: "www.it1995.cn"property int mInt: 88property bool isFemale: falseproperty url mUrl: "http://www.it1995.cn"property var aNumber: 100property var aBool: trueproperty var anotherString: String("#FF008800")property var aColor: Qt.rgba(0.2, 0.3, 0.4, 0.5)property var aRect: Qt.rect(17, 56, 46, 10)property var aPoint: Qt.point(10, 10)property var aSize: Qt.size(10, 10)property var aVector3d: Qt.vector3d(100, 100, 100)property var anArray: [1, 2, 3, "four", "five", (function(){ return "six" })]property var anObject: {"foo": 10, "bar": 20}property var aFunction: (function(){ return "Seven"; })property var aFont: Qt.font({family: "Consolas", pointSize: 30, bold: false})property date mDate: "2019-05-27"Text {id: mTextIDanchors.centerIn: parenttext: mStringfont: aFont}Component.onCompleted: {print("The mUrl is " + mUrl)// var datatypeconsole.log("aNumber is : " + aNumber)console.log("aBool is : " + aBool)console.log("aString is : " + anotherString)console.log("aRect : " + aRect.x + " " + aRect.y)console.log("The length of the array is : " + anArray.length)print("------------------華麗的分割線------------------")anArray.forEach(function(value, index){if(index == 5){console.log(value())}else{console.log(value)}})print("------------------華麗的分割線------------------")for(var i = 0; i < anArray.length; i++){if(i == 5){console.log(anArray[i]())}else{console.log(anArray[i])}}console.log("The date is : " + mDate)console.log("The function value is : " + aFunction())} }?
總結
以上是生活随笔為你收集整理的QML笔记-QML基本数据类型的使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Arduino笔记-温度传感器的使用
- 下一篇: Qt实践| HTTP知识点-接入某图片验