Cannot convert double to QString
I am running Qt 4.2.2 on FreeBSD 4.8 with gcc 3.4.6. I am working with dollar amounts in doubles but I cannot properly convert these doubles into QStrings for display in a QLabel. As a test I compiled the following very simple code:
Code:
#include <QtCore>
int main () {
double doublevar = 42.84;
qDebug
() <<
QString::number(doublevar
);
}
Which outputs "-0" to the terminal. What could be causing this? The same code in this simple program runs fine on my Linux and Windows boxes. If I use a QVariant as below:
Code:
#include <QtCore>
int main () {
double doublevar = 42.84;
qDebug() << var.toString();
}
The output is "-0.00000000005965e+224". Again, what could be wrong?
Thanks
mAx
Re: Cannot convert double to QString
This indeed is strange. The output you experience could be caused by mixups caused by incompatibility between your machine (CPU and OS) and the Qt library, but I think that in this cause nothing should run at all. What is the result of the following?
Code:
double d = 42.84;
qDebug() << d;
Re: Cannot convert double to QString
This
Code:
#include <QtCore>
int main () {
double d = 42.84;
qDebug() << d;
}
still gives "-0"
Thanks
mAx
Re: Cannot convert double to QString
What compiler options do you use, maybe there are some special switches for double floating point (64-bit)?
Re: Cannot convert double to QString
I have not edited the default settings that Qt defaulted to. Here is what is given during a make:
Quote:
g++34 -c -pipe -O2 -Wall -W -pthread -D_THREAD_SAFE -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I../../../local/Trolltech/Qt-4.2.2/mkspecs/freebsd-g++34 -I. -I../../../local/Trolltech/Qt-4.2.2/include/QtCore -I../../../local/Trolltech/Qt-4.2.2/include/QtCore -I../../../local/Trolltech/Qt-4.2.2/include/QtGui -I../../../local/Trolltech/Qt-4.2.2/include/QtGui -I../../../local/Trolltech/Qt-4.2.2/include -I. -I. -I. -I../../../local/include -o foo.o foo.cpp
Thanks
mAx
Re: Cannot convert double to QString
And this one?
Code:
printf("%lf\n", 42.84);
Re: Cannot convert double to QString
Re: Cannot convert double to QString
Did you compile Qt yourself or do you use some precompiled package? What exact architecture do you have? x86?
Re: Cannot convert double to QString
Yes it is x86 and I did compile Qt myself as I could only find Qt 3 for FreeBSD 4.8 in package format.
Thanks
mAx
Re: Cannot convert double to QString
Some ARM installations have floating point implementations that are not fully IEEE-compliant. In Qt/Embedded 3.3.x, this causes QString::number(double) and related functions to give incorrect results. A fix for this was introduced in Qt 3.3.2: defining the macro QT_QLOCALE_USES_FCVT will make Qt use system library code instead, i.e:
./configure -embedded arm -DQT_QLOCALE_USES_FCVT ...
i am in the face of this problem,i have added the macro,but it doesn't work.