Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    QML Type Checking

    QML and Qt Quick
    2
    4
    2721
    Loading More Posts
    • 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
      Tjsail33 last edited by

      Hello again -

      While using a Repeater object and cycling through each index using a for loop, I receive this error on certain computers when it is run, and not on others. Any help with solving this issue would be repeated, as one of the computers that returns this type of error is the one I need to use to showcase the software...

      @file:///XXXXXXXXXX/trunk/Axiom-build-desktop/MainView.qml:146: TypeError: Result of expression 'nodeRepeater.itemAt' [undefined] is not a function.
      @

      Here is the "offending code"

      @
      nodeRepeater.itemAt(i).x = 100;
      nodeRepeater.itemAt(i).y = 100;
      nodeRepeater.itemAt(i).width = appDelegate.getScreenWidth()-200
      nodeRepeater.itemAt(i).height = appDelegate.getScreenHeight() -200
      @

      1 Reply Last reply Reply Quote 0
      • C
        chriadam last edited by

        Can you produce a minimal but complete testcase / qml application which can reliably reproduce this issue? It definitely sounds like a bug. The itemAt function should be provided and available in the scope of the repeater element, so if it cannot find it (hence returning undefined), that suggests either that the type of the nodeRepeater is being somehow changed, or that the JavaScript integration classes are returning the wrong information in some circumstances.

        One "tip" which should also improve performance is: change the code block to be something like:
        var currItem = nodeRepeater.itemAt(i);
        currItem.x = 100; currItem.y = 100; currItem.width = appDelegate.getScreenWidth()-200; currItem.height = appDelegate.getScreenHeight()-200;

        By caching the result of the itemAt lookup, you'll improve performance.

        1 Reply Last reply Reply Quote 0
        • T
          Tjsail33 last edited by

          here is a minimalist version of the code. To be noted - the error is apparent in qt4.7.2, but not in 4.7.4. I am not currently able to update to 4.7.4 on the computers which produce the bug (4.7.2).

          @import QtQuick 1.0

          Rectangle {
          id: fanView1Root
          width: 350
          height: 225
          color: "transparent"
          radius: 20
          border.color: "#FFF"
          border.width: 3

          property int numberOfBlades: 5
          property int bladeHeight: 0
          
          Behavior on width { SmoothedAnimation { velocity:8*50 }}
          Behavior on height { SmoothedAnimation { velocity:5*50 }}
          
          function slideOutBlades() {
              for(var i = 0; i<numberOfBlades; i++) {
                  blades.itemAt(i).appear()
                  lines.itemAt(i).appear()
              }
          }
          
          function retractBlades() {
              for(var i = 0; i<numberOfBlades; i++) {
                  blades.itemAt(i).disappear()
                  lines.itemAt(i).disappear()
              }
          }
          
          Rectangle {
              id: nodeBase
              width: 400
              height: 300
              x: 150
              y: fanView1Root.height/2-height/2
              color: "transparent"
              smooth: true
              radius: 20
              border.color: "#FFF"
              border.width: 2
              visible: false
          
              Text {
                  id: secondaryTitle
                  anchors.centerIn: parent
                  text: "Computer Science Courses"
                  color: "#FFF"
                  visible: false
              }
          }
          
          Repeater {
              id: blades
              model: fanView1Root.numberOfBlades
          
              Rectangle {
                  x: fanView1Root.x+fanView1Root.width
                  y: fanView1Root.y+fanView1Root.height/2
                  radius: 20
                  border.width: 2
                  border.color: "#FFF"
                  color: "grey"
                  width: 0
                  height: 0
          
                  function appear() {
          
                      height = appDelegate.getScreenHeight()/(fanView1Root.numberOfBlades+1)-50
                      x = appDelegate.getScreenWidth()/2-100
                      y = 75+index*(appDelegate.getScreenHeight()/(fanView1Root.numberOfBlades+1)-50)+25*index
                      width = appDelegate.getScreenWidth()/2-150
                      fanView1Root.bladeHeight = height
                  }
          
                  function disappear() {
                      x = fanView1Root.x+350
                      y = fanView1Root.y+225/2
                      width = 0
                      height = 0
                  }
          
                  Behavior on width { SmoothedAnimation { duration:1500 }}
                  Behavior on height { SmoothedAnimation { duration:1500 }}
                  Behavior on x { SmoothedAnimation { duration:1500 }}
                  Behavior on y { SmoothedAnimation { duration:1500 }}
          
              }
          }
          
          Text {
              id: title
              anchors.centerIn: parent
              text: "Computer Science Courses"
              color: "#FFF"
          }
          

          }@

          1 Reply Last reply Reply Quote 0
          • C
            chriadam last edited by

            Ah. I think itemAt() was added in QtQuick 1.1. It sounds likely that the Qt 4.7.4 version shipped with QtQuick 1.1 and the 4.7.2 version shipped with QtQuick 1.0. If you change the import statement to 1.1, you'll get a much more noticeable error on the 4.7.2 machines ;-)

            Note that 1.1 is backward compatible with 1.0, but the reverse isn't true (hence why importing 1.0 on a 1.1-capable system works).

            1 Reply Last reply Reply Quote 0
            • First post
              Last post