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. Change property more than one time in an qml depend on input variables
Forum Updated to NodeBB v4.3 + New Features

Change property more than one time in an qml depend on input variables

Scheduled Pinned Locked Moved QML and Qt Quick
16 Posts 4 Posters 4.5k 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.
  • P Offline
    P Offline
    petzold
    wrote on last edited by
    #7

    no i have bit values and this i want transform to a number. not the matter if the number is hex, bin, dec.
    i do it now in that way i think it will work
    @
    Text {
    id: elevatorName
    text: {
    if(boCodePin3 == FALSE && boCodePin4 == FALSE) return "MEC1";
    else if (boCodePin3 == TRUE && boCodePin4 == FALSE) return "MEC2";
    else if (boCodePin3 == FALSE && boCodePin4 == TRUE) return "MEC3";
    else if (boCodePin3 == TRUE && boCodePin4 == TRUE) return "MEC4";
    }
    }
    @

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #8

      Huh? What you are doing now is not converting to a number, but to a string.

      It seems you have a collection of booleans. I'd just make a simple element in C++ that you then expose to QML that has boolean properties for every bit position you want to support (8,16, perhaps more?) and an integer property for the numeric interpretation. You can then just bind your boolean values to this object hand use binding to the numeric value too. Or use it the other way around to set a number and get the induvidual bits directly. Edit: you could just make that component completely in QML too, if you want.

      What you now write is feasible (but not recommended) if you have just two, maybe three bits. After that, it gets rather long and easy to make mistakes in quickly. Doing this for 8 bits will already require 256 of these with 8 checks each. Good luck with that...

      1 Reply Last reply
      0
      • p3c0P Offline
        p3c0P Offline
        p3c0
        Moderators
        wrote on last edited by
        #9

        Still not able to understand. Can you give an example of what input you get and what you want it to be converted into ?

        157

        1 Reply Last reply
        0
        • P Offline
          P Offline
          petzold
          wrote on last edited by
          #10

          Andre:
          i know this solutionwill just work in that simple case,and i don't want it too. that was the reason to post the problem. :-)
          the solution will work because i just have 4 bits and so i can handle it.

          your idea i don't understand fully. can you please detail it more or give a example, link etc?

          p3c0:
          a controller collect some differnt signals for controlling and visualization this are send over and interface to a control programm. some of this information are for the controlling, the rest is for visualization.
          the problem is i don't want to change the programm code, the code should be the same becuase in other cases i need the bits.

          this 4 bits are digital inputs and used for visualization.
          this 4 bits are the coding of 16 sockets. and i will make a view where the user can see wich socket is used.

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #11

            So what numerical input you get when for eg socket no. 8 is used ? Do you get 1000 (considering each digit as a separate bit ofcourse)as the input ?

            157

            1 Reply Last reply
            0
            • P Offline
              P Offline
              petzold
              wrote on last edited by
              #12

              for socket 8 i get

              boBit0 = FALSE
              boBit1 = FALSE
              boBit2 = FALSE
              boBit4 = TRUE

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #13

                I'd do something like this:

                Make new QML file BitField.qml, and put something like this in (untested):

                @
                import QtQuick 2.2

                QtObject {
                id: BitField
                property bool bit0
                property bool bit1
                property bool bit2
                property bool bit3

                property int value;

                onBit0Changed: updateValue()
                onBit1Changed: updateValue()
                onBit2Changed: updateValue()
                onBit3Changed: updateValue()

                function updateValue() {
                int newVal = 0;
                newVal |= bit0 ? 1 : 0;
                newVal |= bit1 ? 2 : 0;
                newVal |= bit2 ? 4 : 0;
                newVal |= bit3 ? 8 : 0;
                value = newVal;
                }

                onValueChanged: {
                bit0 = value && 1;
                bit1 = value && 2;
                bit2 = value && 4;
                bit3 = value && 8;
                }
                }
                @

                You can then use the BitField element in your QML, and just bind to the properties however you like.

                Again: the code above is an idea only, I did not test it but just typed it into the forum editor directly.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  petzold
                  wrote on last edited by
                  #14

                  this is my idea to solve it. (tested)

                  @
                  function iTransformtoInt(bit0, bit1, bit2, bit3, bit4, bit5, bit6, bit7) {
                  var calc = 0;
                  if (bit0 === true) { calc +=1};
                  if (bit1 === true) { calc +=2};
                  if (bit2 === true) { calc +=4};
                  if (bit3 === true) { calc +=8};
                  if (bit4 === true) { calc +=16};
                  if (bit5 === true) { calc +=32};
                  if (bit6 === true) { calc +=64};
                  if (bit7 === true) { calc +=128};
                  return calc;
                  }
                  Text {
                  id: elevatorName
                  text: iTransformtoInt(boCodePin1,boCodePin2, boCodePin3, boCodePin4,0,0,0,0)

                  }
                  @

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    petzold
                    wrote on last edited by
                    #15

                    thanks you both for give me some new ideas.

                    1 Reply Last reply
                    0
                    • p3c0P Offline
                      p3c0P Offline
                      p3c0
                      Moderators
                      wrote on last edited by
                      #16

                      Or may be this one
                      @
                      function convert(pinsArray) {
                      var all = ""
                      for(var i=0;i<pinsArray.length;i++)
                      all += (pinsArray[i]*1).toString()

                      console.log(all,parseInt(all, 2))
                      

                      }

                      Component.onCompleted: {
                      var boCodePin1 = false
                      var boCodePin2 = false
                      var boCodePin3 = false
                      var boCodePin4 = true

                      var arr = [boCodePin4,boCodePin3,boCodePin2,boCodePin1];
                      convert(arr)
                      

                      }
                      @

                      seems the earlier post was deleted.

                      157

                      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