Qt.point() in QML
-
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_1then 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 undefinedWhat is the problem, and how to achieve that goal, please?
-
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_1then 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 undefinedWhat is the problem, and how to achieve that goal, please?
@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.
-
@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.
@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? -
@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?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 rRYPointThen when collision occurs:
rRYPoint = rightRacket.yThen 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