QML: How to do variables?
12,797
You can use QML basic types or the generic var property.
The var type is a generic property type that can refer to any data type.
It is equivalent to a regular JavaScript variable. For example, var properties can store numbers, strings, objects, arrays and functions.
The following code will demonstrate the use of both basic types and var properties:
import QtQuick 2.0
import Ubuntu.Components 0.1
Rectangle {
id: mainView
width: units.gu(30)
height: units.gu(40)
Item {
id: myItem
property int aNumber: 100
property bool aBool: false
property string aString: "Hello world!"
property var aVarNumber: 100
property var aVarBool: false
property var aVarString: "Hello world!"
}
Component.onCompleted: {
console.log(myItem.aNumber, myItem.aVarNumber)
console.log(myItem.aBool, myItem.aVarBool)
console.log(myItem.aString, myItem.aVarString)
}
}
Source: http://qt-project.org/doc/qt-5/qtqml-typesystem-basictypes.html
Author by
Anon
Specialties: Keyboard Layouts Audiobooks and Text to Speech Qt
Updated on September 18, 2022Comments
-
Anon almost 2 years
In QML, I am just looking for a way to do fairly simple variables:
- Bool
- String
- Integer