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. Naming conventions in QML
Forum Updated to NodeBB v4.3 + New Features

Naming conventions in QML

Scheduled Pinned Locked Moved QML and Qt Quick
8 Posts 3 Posters 4.8k Views 1 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.
  • S Offline
    S Offline
    situ117
    wrote on last edited by
    #1

    Hi,

    Is there any list of naming conventions in QML ? QML's coding conventions page at http://doc.qt.nokia.com/latest/qml-coding-conventions.html does not say anything about naming conventions.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      DenisKormalev
      wrote on last edited by
      #2

      Because it is really similar to Qt naming conventions maybe?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        situ117
        wrote on last edited by
        #3

        Actually I find it a little different. So let's say I create my own component which contains other elements:
        @
        MyRectangle {
        id: ????
        width: 80; height: 80

        Item {
        //item1
        }
        
        Item {
        //item2
        }
        

        }
        @
        Now what should be the default id for MyRectangle ? Should it be "container" or "myRectangle". container is the one used by QML examples at many places for elements which contain other elements.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DenisKormalev
          wrote on last edited by
          #4

          I'm not sure it should be covered with naming convention.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            situ117
            wrote on last edited by
            #5

            Since all the names in QML are kind of "global"; the only way to avoid naming conflicts is by following strict naming conventions. It's possible to declare two different elements with same name. Which name would be visible if I use them at third place ? Does it only depend upon order of declaration of elements ?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mbrasser
              wrote on last edited by
              #6

              Hi,

              If you create a MyRectangle.qml as follows:

              @
              //MyRectangle.qml
              Rectangle {
              id: ????
              width: 80; height: 80

              Item {
                  id: item1
              }
               
              Item {
                  id: item2
              } 
              

              }
              @

              The id you assign to the top level Rectangle will not be visible "outside" the component. For example, in the following case:

              @
              //main.qml
              Item {
              MyRectangle {}
              }
              @

              the id assigned to the Rectangle in MyRectangle.qml will not be visible in main.qml. Does this answer your question about naming conflicts/visibility, or was there a different case you were concerned with?

              Regards,
              Michael

              1 Reply Last reply
              0
              • S Offline
                S Offline
                situ117
                wrote on last edited by
                #7

                Hi,

                Can you provide me any page which explains how names are managed and shadowed in QML ?

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mbrasser
                  wrote on last edited by
                  #8

                  Hi,

                  The scope documentation can be found at http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescope.html -- I think this should have the information you are after.

                  Regards,
                  Michael

                  1 Reply Last reply
                  0

                  • Login

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