Important: Please read the Qt Code of Conduct -

QVector3D maths in QML

  • Hello,

    I have the following piece of code:
    @function move(length){
    var direction = cam.eye -;
    cam.eye += direction * length; += direction * length;

    cam is a Camera object (from Qt3D), and thus cam.eye and are vector3d's.

    The piece of code is supposed to move the eye (user) towards the center point, and also moving the center point, so that we don't get errors when reaching it.

    length specifies the length to move.

    The problem is I get the following error for line 3 in the above code:
    @Error: Cannot assign QString to QVector3D@

    I am not to confident with QML yet, so it probably is something very simple.


  • Hi,

    Javascript does not support operator overloading the way C++ does, so +/-/* do not perform vector manipulations the way you'd expect.

    For QtQuick 2.0 a number of functions have been added (see for details) to handle this. For QtQuick 1.x you may need to manipulate the sub-values directly (or Qt3D may provide more convenient ways of handling this, I'm not sure).


Log in to reply