Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Assigning values to an array, values not kept?
Forum Updated to NodeBB v4.3 + New Features

Assigning values to an array, values not kept?

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k 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.
  • W Offline
    W Offline
    woofy
    wrote on last edited by
    #1

    I can assign values to a variable property but not to an array here? ... values aren't kept.

    @ Column {
    id: table

         property variant aa: [false, false] //issue... later
         property variant bb: false //this works
    
         ...
    
         Button {
            anchors.top: parent.top
            anchors.topMargin: 0//40
            anchors.right: parent.right
            anchors.rightMargin: 0//50
            corpFarmAware: true
            text: tr_NOOP("Next")
    
            onClicked: {
                table.aa[0] = false;
                table.aa[1] = true;
                cb0.checked = table.aa[0];//issue of arrays ??
                cb1.checked = table.aa[1];
    
                table.bb = true;
                cb2.checked = table.bb;//WORKS
            }
        }@
    

    Also note that I will be modifying table.bb though out the code. This is watered down.

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

      I'm sorry but I don't see what the issue is... are you getting any errors, or aa[0] has some unexpected value, or what?

      (Z(:^

      1 Reply Last reply
      0
      • W Offline
        W Offline
        woofy
        wrote on last edited by
        #3

        I can assign to it initially. But after that I can't re-assign. After reading some documentation, it seems you can't re-assign to individual elements for lists, variants.

        I have an array of buttons created with Repeater, but indexAt is not available. So since I couldn't index them I wanted to create an array to store/modify the selections. Can't seem to do either case.

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

          You still have not given any error messages or such ;) I want to help, but I need information :D

          It's been a while since I've worked with JS arrays, but I'll try to recall my findings. First, you should be using "var" property instead of a variant (in Qt5). It handles JS objects better.

          Next, IIRC what I was doing was something like this:
          @
          property var myProperty: new Array()

          Component.onCompleted: {
          myProperty.push("blah");
          }

          // ...
          onClicked: {
          table.myProperty[0] = false;
          }
          @

          (Z(:^

          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