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. Qt.point() in QML
Forum Updated to NodeBB v4.3 + New Features

Qt.point() in QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 Posters 653 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
    tomy
    wrote on 10 Feb 2019, 16:30 last edited by
    #1

    Hello,

    I searched much to find a simple way to use Qt.point in QML but couldn't attain it, unfortunately.

    At the beginning of a main.qml component there's this declaration:

    property var test_1
    

    then in below is a function where I have assigned the x and y of another component to it this way:

    test_1 = Qt.point(rightRacket.x,rightRacket.y)
    

    Afterwards, in some other part in the current main.qml component, I wanted to print those coordinates this way:

    console.log("test_1:", test_1.x, test_1.y)
    

    But I get an error asserting:
    TypeError: Cannot read property 'x' of undefined

    What is the problem, and how to achieve that goal, please?

    O 1 Reply Last reply 10 Feb 2019, 16:59
    0
    • T tomy
      10 Feb 2019, 16:30

      Hello,

      I searched much to find a simple way to use Qt.point in QML but couldn't attain it, unfortunately.

      At the beginning of a main.qml component there's this declaration:

      property var test_1
      

      then in below is a function where I have assigned the x and y of another component to it this way:

      test_1 = Qt.point(rightRacket.x,rightRacket.y)
      

      Afterwards, in some other part in the current main.qml component, I wanted to print those coordinates this way:

      console.log("test_1:", test_1.x, test_1.y)
      

      But I get an error asserting:
      TypeError: Cannot read property 'x' of undefined

      What is the problem, and how to achieve that goal, please?

      O Offline
      O Offline
      ODБOï
      wrote on 10 Feb 2019, 16:59 last edited by
      #2

      @tomy hi,

      ApplicationWindow {
          id: window
          visible: true
          width: 600
          height: 200
          property var mypoint //: Qt.point(Math.random(),Math.random())
      
          Component.onCompleted: {
              mypoint = Qt.point(Math.random(),Math.random())
              console.log(mypoint.x)
          }
      }
      

      This works perfectly.

      @tomy said in Qt.point() in QML:

      TypeError: Cannot read property 'x' of undefined

      this is saying your test_1 is undefined.

      T 1 Reply Last reply 10 Feb 2019, 17:29
      0
      • O ODБOï
        10 Feb 2019, 16:59

        @tomy hi,

        ApplicationWindow {
            id: window
            visible: true
            width: 600
            height: 200
            property var mypoint //: Qt.point(Math.random(),Math.random())
        
            Component.onCompleted: {
                mypoint = Qt.point(Math.random(),Math.random())
                console.log(mypoint.x)
            }
        }
        

        This works perfectly.

        @tomy said in Qt.point() in QML:

        TypeError: Cannot read property 'x' of undefined

        this is saying your test_1 is undefined.

        T Offline
        T Offline
        tomy
        wrote on 10 Feb 2019, 17:29 last edited by
        #3

        @LeLev

        But I have declared it under ApplicationWindow, property var test_1, and lower inside a function, test_1 = Qt.point(rightRacket.x,rightRacket.y), and lower than that inside another function, console.log("test_1:", test_1.x, test_1.y). So is it undefined?

        T 1 Reply Last reply 10 Feb 2019, 18:08
        0
        • T tomy
          10 Feb 2019, 17:29

          @LeLev

          But I have declared it under ApplicationWindow, property var test_1, and lower inside a function, test_1 = Qt.point(rightRacket.x,rightRacket.y), and lower than that inside another function, console.log("test_1:", test_1.x, test_1.y). So is it undefined?

          T Offline
          T Offline
          tomy
          wrote on 10 Feb 2019, 18:08 last edited by tomy 2 Oct 2019, 18:41
          #4

          Since I only need the y position of the a racket at the collision time and it's one number, I replaced the Qt.point with a real number:

          property real rRYPoint
          

          Then when collision occurs:

          rRYPoint = rightRacket.y
          

          Then the collision took place two times but console.log("The x position of rightRacket:", rRYPoint) wrote the following for both the two!

          qml: The y position of rightRacket: 0

          1 Reply Last reply
          0

          1/4

          10 Feb 2019, 16:30

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved