문제

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?

도움이 되었습니까?

해결책

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).

다른 팁

You can also use the QString::number function if you need specific formatting. Unfortunately, I wasn't able to find anything more efficient than this method

 QString("X:%1Y:%2Z:%3").arg(QString::number(location.x()), QString::number(location.y()), QString::number(location.z()));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top