读书人

qreal怎么转换到QString

发布时间: 2012-09-14 11:53:44 作者: rapoo

qreal如何转换到QString
错误: 对成员‘toString’的请求出现在‘((QBBall*)this)->QBBall::position.QPointF::y()’中,而后者具有非类类型‘qreal’
该如何转化呢,想了半天也没找到方法。

[解决办法]
typedef qreal
Typedef for double on all platforms except for those using CPUs with ARM architectures. On ARM-based platforms, qreal is a typedef for float for performance reasons.

所以你可以使用
QString QString::number ( double n, char format = 'g', int precision = 6 ) [static]
This is an overloaded member function, provided for convenience.
Returns a string equivalent of the number n, formatted according to the specified format and precision. The format can be 'f', 'F', 'e', 'E', 'g' or 'G' (see the arg() function documentation for an explanation of the formats).
Unlike QLocale::toString(), this function does not honor the user's locale settings.
See also setNum() and QLocale::toString().

读书人网 >C++

热点推荐