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. Repeater::itemAt access to non-Item properties
Forum Updated to NodeBB v4.3 + New Features

Repeater::itemAt access to non-Item properties

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 3.1k 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
    pawelbial
    wrote on last edited by
    #1

    Hello.

    I define Block element and I use it with repeter:
    @
    Grid {
    id: answerGrid
    ...
    Repeater {
    id: rep
    model: 3
    Block {
    }
    @

    When I use itemAt function:

    @rep.itemAt(i)@

    It return a Item object. And I can't access to variable with I add to Block item.

    Is there any simple way to access it?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hello,

      that's strange. I used this and I did not have any problems. (http://developer.qt.nokia.com/wiki/QML_Scrolling_Digits)

      Can you show more code or if there are some errors in output?

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

      • Linu...
      1 Reply Last reply
      0
      • P Offline
        P Offline
        pawelbial
        wrote on last edited by
        #3

        I create sample project
        main.cpp
        @import QtQuick 1.1
        import "Addons" as Addons

        Rectangle {
        id: board
        (color, width ...)
        Grid {
        id: answerGrid
        (anchors)
        columns: 6
        rows: 6
        spacing: 7

            Repeater {
                id: blocks
                model: 36
                Addons.Block{
                    id: block
                }
            }
        }
        

        }
        @

        Addons/block.qml
        @
        import QtQuick 1.1

        Rectangle {
        id: block
        (width,height...)
        Grid {
        property int row: Math.floor(index/answerGrid.columns)
        property int col: index-row*answerGrid.columns
        id: cellGrid
        (anchors)
        columns: 3
        rows: 2
        spacing: 2
        Repeater {
        id :repro
        model: 6
        Rectangle {
        id: cell
        (width,height,color)

                    Text{
                        id: num
                        (anchors)
                        text: index
                    }
                    MouseArea{
                        id: cellMouse
                        anchors.fill: parent
                        onClicked: {
                           console.log(blocks.itemAt(0).cellGrid)
                           blocks.itemAt(0).cellGrid.rows = 5
                        }
                    }
                }
            }
        }
        

        }
        @

        Conslole.log returns undefined value.
        Next line return
        @Addons/Block.qml:40: TypeError: Result of expression blocks.itemAt(0).cellGrid' [undefined] is not an object.@

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

          Hello,

          blocks is id from main.qml and it is not visible in block.qml See "Component scope":http://doc.qt.nokia.com/4.7-snapshot/qdeclarativescope.html#component-scope

          "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

          • Linu...
          1 Reply Last reply
          0
          • P Offline
            P Offline
            pawelbial
            wrote on last edited by
            #5

            Thanks for replay :) Still I don't really undestand what element's are visible and with are not. I was able to access board.width or answerGrid.columns from block.qml with propably shoudn't be possible.

            I solved problem with access to the element using itemAt.
            When I used @console.log(blocks.itemAt(0).repro)@ it return undefined, but when I add @property alias repro: repro@ to block.qml it return right object.

            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