Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Semicolons in QML
Forum Updated to NodeBB v4.3 + New Features

Semicolons in QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 3 Posters 998 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    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?

    KroMignonK JKSHJ 2 Replies Last reply
    0
    • C Circuits

      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?

      KroMignonK Offline
      KroMignonK Offline
      KroMignon
      wrote on last edited by KroMignon
      #2

      @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 like Component.onCompleted. For single commands they are optional.

      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

      1 Reply Last reply
      4
      • C Circuits

        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?

        JKSHJ Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by JKSH
        #3

        @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"
        

        Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved