PDA

View Full Version : Calling object's operator+ from QtScript



PolyVox
30th June 2010, 22:32
Hi Guys,

I hope this isn't a stupid question but I'm failing to call the 'operator+' for a QVector3D from my QtScript code. Rather than adding the together the numerical values of each, it instead generates string representations and concatenates them. My code:

var vec1 = new QVector3D(1.0,2.0,3.0);
var vec2 = new QVector3D(4.0,5.0,6.0);
print('Sum is ', vec1 + vec2);

It prints "Sum is QVector3D(1, 2, 3) QVector3D(4, 5, 6)" whereas the desired result would be "Sum is QVector3D(5, 7, 9)".

So any idea if/how I can call the operator+ forthis class from QtScript? I think there is a clue here (http://doc.qt.nokia.com/4.6/scripting.html#checking-the-types-of-arguments) but I don't quite get it...

Thanks!

PolyVox
1st July 2010, 22:37
Anyone?

I guess I could subclass QVector3D and create member functions called add(), multiplyBy(), etc, but it seems like there should be a way to just use the overloaded operators...