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. [Solved] Calculation in a QML file?
Forum Updated to NodeBB v4.3 + New Features

[Solved] Calculation in a QML file?

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.9k 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.
  • T Offline
    T Offline
    Thanana
    wrote on last edited by
    #1

    Hello all,

    I got the following code that doesn't work (in a QML file - PixelAdapter.qml) :

    @Item {
    id: pixelAdapterId

    property int in
    property int alpha
    property int out
    
    out = in * 10 + alpha
    

    }@

    I tried :

    @pixelAdapterId.out = pixelAdapterId.in * 10 + pixelAdapterId.alpha

    PixelAdapter.out: PixelAdapter.in * 10 + PixelAdapter.alpha@

    but everything doesn't work. I feel like I'm not doing something usual in QML but I HAVE to do some calculations with my properties, and "bind" the result of it to another property.
    What do I have to modify ?

    Thanks in advance for any help,
    Gui

    1 Reply Last reply
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      @Item {
      id: pixelAdapterId

      property int in: 10
      property int alpha: 20
      property int out: in * 10 + alpha
      

      Component.onCompleted: {
      console.log(out);
      }
      }@

      This example print 120 to console

      --
      Vasiliy

      1 Reply Last reply
      0
      • T Offline
        T Offline
        Thanana
        wrote on last edited by
        #3

        This seems to work but it doesn't... I'll try to explain.
        The thing is that in my software uses 2 bindings with this QML file. One binding is on the "in" value and the other on the "out" value.
        And when I start my software, when I FIRST change my "in" value, the bind on the "out" value gets the new value. This works.
        But when I change the value again, the "out" doesn't update... and the thing is that the value will constantly change in my software :/

        Does someone got an idea about it ?

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          For every property in QML you automatically get chadged signal, so you can try use something like:

          @Item {
          id: pixelAdapterId

          property int in
          property int alpha: 20
          property int out
          .....
          function calcOut() {
             out = in * 10 + aplha
          }
          onInChanged: {
             calcOut()
          }
          .....     
          

          }@

          --
          Vasiliy

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #5

            [quote author="Thanana" date="1318406351"]This seems to work but it doesn't... I'll try to explain.
            The thing is that in my software uses 2 bindings with this QML file. One binding is on the "in" value and the other on the "out" value.
            And when I start my software, when I FIRST change my "in" value, the bind on the "out" value gets the new value. This works.
            But when I change the value again, the "out" doesn't update... and the thing is that the value will constantly change in my software :/

            Does someone got an idea about it ?[/quote]

            Use @Behaviour on in { /* some code here */ }@ It will be invoked every time when you change "in".

            (Z(:^

            1 Reply Last reply
            0
            • T Offline
              T Offline
              Thanana
              wrote on last edited by
              #6

              Both works, thanks a lot to both of you :)

              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