Solved Semicolons in QML
-
Hey guys, just a general question here about the use of semicolons. Now, from what I understand in JS the semicolon is optional save for a few special cases. Is the same true for QML? For instance, take the following code snip:
Component.onCompleted: { state = "selection"; }
this seems to work exactly the same as:
Component.onCompleted: state = "selection"
is there a valid argument for the first case over the second in QML?
-
@Circuits said in Semicolons in QML:
Hey guys, just a general question here about the use of semicolons. Now, from what I understand in JS the semicolon is optional save for a few special cases. Is the same true for QML?
Yes
For instance, take the following code snip:
Component.onCompleted:
{
state = "selection";
}this seems to work exactly the same as:
Component.onCompleted: state = "selection"It is exactly the same.
is there a valid argument for the first case over the second in QML?
No, only developer preferences.
With semi-colons you can add more commands on one line.
Brackets are required when using multiple commands for a connection on a signal likeComponent.onCompleted
. For single commands they are optional. -
@Circuits said in Semicolons in QML:
Hey guys, just a general question here about the use of semicolons. Now, from what I understand in JS the semicolon is optional save for a few special cases. Is the same true for QML?
Yes
For instance, take the following code snip:
Component.onCompleted:
{
state = "selection";
}this seems to work exactly the same as:
Component.onCompleted: state = "selection"It is exactly the same.
is there a valid argument for the first case over the second in QML?
No, only developer preferences.
With semi-colons you can add more commands on one line.
Brackets are required when using multiple commands for a connection on a signal likeComponent.onCompleted
. For single commands they are optional. -
@Circuits said in Semicolons in QML:
is there a valid argument for the first case over the second in QML?
Note: The code to the right-hand-side of
:
is a JavaScript statement. So, you follow the JavaScript rules of braces and semicolons.The following snippets are all exactly the same. Like @KroMignon said, just choose the one you prefer.
// Style 1 Component.onCompleted: { state = "selection"; } // Style 2 Component.onCompleted: { state = "selection" } // Style 3 Component.onCompleted: { state = "selection"; } // Style 4 Component.onCompleted: { state = "selection" } // Style 5 Component.onCompleted: state = "selection"; // Style 6 Component.onCompleted: state = "selection"