0

I tried to output a long double to the console directly using qDebug() and indirectly via QString::number() but both do not accept long double.

Is it true that there is no easy way of printing a long double floating point number to the console using Qt? Why?!

4

2 回答 2

2

You can provide your own overload of operator<<():

QDebug& operator<<(QDebug& d, long double f)
{
    return d << static_cast<double>(f);
}

This won't show you any extra precision, of course, but may be what you need.

Be aware, however, that a future version of Qt might implement such a function, putting you in violation of the One-Definition Rule. To avoid this, you should guard it with an appropriate #if test for the exact Qt version (or range of versions) that you have verified do not provide a conflicting definition. Also, please consider contributing your implementation to Qt.

于 2016-07-12T22:21:43.047 回答
0

There's no overarching reason. At least as of Qt 5.6, nobody bothered to implement it. That's all.

于 2016-07-12T22:00:07.993 回答