[Prev: Qt Script Language Concepts] [Home] [Next: Classes and Methods]
identifiers match the regex pattern [_A-Za-z][_A-Za-z0-9]*. Identifiers are used for variables, constants, class names, function names and labels.
reserves some words which are valid identifiers for its own use. See the Built-in Functions and Operators chapter for the complete list.
Variables are declared using the var keyword:
var a; // undefined var b : Integer; // undefined var c = "foliage"; var d : String = "silver birch"; x = 1; // global variable
If a variable has a type specified, i.e. by appending ': typename' after its name, only objects of the given type should be assigned to the variable. Variables declared with var are local to their enclosing block.
If a variable is assigned to without being declared, it is automatically declared as a global variable. Using global variables can make your code difficult to debug and maintain and is not recommended.
Constants are declared using the const keyword:
const x = "Willow"; const y : String = "Oak";
Constants must be defined at the point of declaration, because they cannot be changed later. If an attempt is made to assign to a constant, the interpreter will issue an error message and stop.
Constants are public globals if they are declared outside of any enclosing braces. When declared within the scope of some braces, e.g. within an if statment, their scope is local to the enclosing block.
[Prev: Qt Script Language Concepts] [Home] [Next: Classes and Methods]