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. When to use ':' versus '='?

When to use ':' versus '='?

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 902 Views
  • 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.
  • T Offline
    T Offline
    treaves
    wrote on last edited by
    #1

    I'm learning QML. I'm playing with an application that uses a ListView, and I'm using a delegate. In all of this QML, properties are set using a ':'.

    I wanted to know how to do something when a delegate was tapped, and I found some code that does it. But in that code is the line

    list_view1.currentIndex = index
    

    My question is why in this case is '=' used instead of ':'? And more generally, when is each appropriate? I can't seem to find this in the documentation.

    Thanks.

    JKSHJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Because it's assigning index to currentIndex, it's not setting its property.

      : is used when you set the properties when declaring the object. For the rest of the code, you can't do that.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T treaves

        I'm learning QML. I'm playing with an application that uses a ListView, and I'm using a delegate. In all of this QML, properties are set using a ':'.

        I wanted to know how to do something when a delegate was tapped, and I found some code that does it. But in that code is the line

        list_view1.currentIndex = index
        

        My question is why in this case is '=' used instead of ':'? And more generally, when is each appropriate? I can't seem to find this in the documentation.

        Thanks.

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

        Hi,

        @treaves said:

        My question is why in this case is '=' used instead of ':'?

        Because that is JavaScript code, and JavaScript only lets you assign values using '='.

        And more generally, when is each appropriate?

        ':' has a few different uses in QML. In your case, ':' performs a property binding. In contrast, '=' performs an assignment.

        See http://doc.qt.io/qt-5/qtqml-syntax-propertybinding.html for an explanation of property bindings.

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

        1 Reply Last reply
        1
        • T Offline
          T Offline
          treaves
          wrote on last edited by
          #4

          Thank you both for your responses. I also appreciated the link; reading that helped a lot.

          I'll brush up on JavaScript.

          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