Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Output QVector3D to QString

Tags:

c++

qt

qstring

I was surprised to learn that QVector3D does not have a built-in way of outputting the x, y, and z coordinates as a QString. I can write a simple function to do this, but I was wondering if there was a standard method of doing it?

like image 659
user_123abc Avatar asked Aug 18 '11 18:08

user_123abc


1 Answers

You can use QDebug::QDebug(QString*) and the operator << from QDebug :

QString str;
QDebug(&str) << QVector3D(1,2,3);

But because that constructor is not declared explicit, you can omit the QDebug:

QString str;
&str << QVector3D(1,2,3);

(I don't know if this is a bug or a feature, and if you can rely on that second form in future versions of Qt).

like image 175
alexisdm Avatar answered Sep 28 '22 22:09

alexisdm