-
use QString::number ( double n, char format = 'g', int precision = 6 )
hi, i find a very strange thing, i use QString::number ( double n, char format = 'g', int precision = 6 ) to show a double type data, the program is run in PC normal, but it run in ARM board, it show -0, and then the program is die, the cpu is up to 85%. but when i use QString::number ( int n, int base = 10 ) , is mean show int type data, the program run in PC or ARM board is well. this is why, and have any method to show double type. thanks.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
Most likely you have the wrong version of code somewhere and there's a mismatch in terms of the number of physical words of parms passed for the double value.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
What does your code actually look like? Where has the double value come from? Does this work as expected:
Code:
#include <QtCore>
#include <QDebug>
int main (int argc, char *argv[])
{
double value = 3.14159265;
qDebug
() <<
QString::number(value,
'g',
6);
return 0;
}
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
yea, my code is like with you, but the value is not expected, it will change everytime,
this is my code
Code:
int fValue; //fValue will changed in other place
mStrContext
= QString::number(fValue
/10.0,
'g',
3);
pp.drawText(x, y, mStrContext);
when i use qDebug() print the (fValue/10.0) is also be die.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
Is your program crashing or are you just getting unexpected results? If the program is crashing then it is very unlikely that QString::number is involved.
If the value you get out each time is different then it is likely that fValue is not being initialised before you use it (it isn't in your example).
Compile and run my test program on your embedded system. Does it print:
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
the program is die, the cpu is up to 85%. when i comment
Code:
mStrContext
= QString::number(fValue
/10.0,
'g',
3);
this code, the program run normal. and the fValue is initialized ine the construct function. so it impossible not being initialized before use.
let me run you program, then give you result. thanks
Added after 46 minutes:
in my board it print 4.14378e+95, it very interesting.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
Can you single step through the test program with a debugger? What does the debugger think the value is?
Does the ARM architecture support doubles (Does it work with float)? Are you generating code that matches your architecture and floating point ABI?
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
1. debug on device (I assume that you have debugged on x86)
2. Qt has small mess with usage of qreal/double, note that qreal on ARM architecture is a float (on other platforms it is a double). In your case (QString::number) double is always used so it should work.
3. Write qtest and if you can reproduce it with a qtest report a bug to qt (Nokia) (include test to report).
I'm pretty sure that this functionality was tested on all platforms so it looks strange that you have a problem with it (see http://qt.gitorious.org/qt/qt/blobs/...g.cpp#line3558 http://qt.gitorious.org/qt/qt/blobs/...g.cpp#line2263).
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
yea, thanks remind me, i think the ARM do not support double, before i test by small example, it reproduce same proglem, but the example run in PC, it nothing happened. thanks your help.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
sorry, i guess is wrong, the ARM9 support soft double type, and i write a sample, the code is
Code:
#include <stdio.h>
int main()
{
double a = 3.1415926;
double b = 4.57283;
double result;
result = a/b;
printf("a=%f, b=%f, result=%f\n", a, b, result);
return 0;
}
use arm-linux-gcc-4.3.3 compile, and then let run in ARM board, the printed result is true.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
Depending on the compiler used, "fValue/10.0" will compile to different sized values. Probably technically a bug, but the compiler writer will tell you it's a "feechure". Assign the result to a temp and use the temp:
Code:
double tempDbl = fValue/10.0;
mStrContext
= QString::number(tempDbl,
'g',
3);
Quote:
Originally Posted by
lzpmail
yea, my code is like with you, but the value is not expected, it will change everytime,
this is my code
Code:
int fValue; //fValue will changed in other place
mStrContext
= QString::number(fValue
/10.0,
'g',
3);
pp.drawText(x, y, mStrContext);
when i use qDebug() print the (fValue/10.0) is also be die.
(Actually, it probably isn't technically a compiler bug. "fValue/10.0" can legally compile to a float, not a double.)
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
Nope you are wrong. C standard says that literal like "10.0" is treated as a double number so you have int/double and this is a double.
Another thing is prototype of QString::number, the only floating point version is version with double (not with qreal) so should work same on ARM as on other platforms.
Like I suggested until program wan't be debugged on arm or some unit test written which proves error in Qt I would assume bug in application not in Qt.
Or maybe you (lzpmail) should give us wider context of usage.
-
Re: use QString::number ( double n, char format = 'g', int precision = 6 )
thanks your help, this probram is solved, but i use another method to solve this probram(use sprintf function to change double to char *), but i will continue find the reason, if i find i will tell yours.
-
QString::number ( double n, char format = 'g', int precision = 6 )title talk again
hi, before i paste QString::number ( double n, char format = 'g', int precision = 6 ), this problem may have solved, before i use qt 4.5 to compile my program, have problem in ARM board, now i use qt 4.7 to compile, no that problem.
-
Re: QString::number ( double n, char format = 'g', int precision = 6 )title talk agai
Is there a question here somewhere?
-
Re: QString::number ( double n, char format = 'g', int precision = 6 )title talk agai
No, I don't think so. lzpmail is just sharing the happy news that the problem from here has been solved.
-
Re: QString::number ( double n, char format = 'g', int precision = 6 )title talk agai