PDA

View Full Version : qsqlquery problem, i cant get my real value from database, please help...



azuraZelda
11th July 2011, 06:37
hello all, im sorry if my english language is not good,,
here is my problem, i want to get the real value from field in database..

here it's source:



QSqlQuery queryLat;
qreal latPoint;
i=1

//how to get the real latitude value from database???
queryLat.prepare( "select latPOI from tabPOI where id in (:states)");
queryLat.bindValue(":states", i);
queryLat.exec();
qDebug() << "LATITUDE";
while( queryLat.next() ) {
latPoint = queryLat.value(0).toDouble();
qDebug() << "latPoint = " << latPoint;
}
qDebug() << "LATITUDE";



the real value in my database is: latPOI=52.7849587483 (12digits)
but with that source i only get value with 6 digits :


latPoint = 52.7849

my question is, how i can get the real value of my database??? i need all of digit in this value (12digits)....

please help me...

mcosta
11th July 2011, 07:53
It depends from numeric precision.
I don't know how to set in qDebug but std::cout use 6 digit precision.
In Database the data type used depends from the driver, in some case you have to use QString to achieve the best precision (for ORACLE NUMERIC for example).

azuraZelda
11th July 2011, 08:00
thx for replying..
i need value of double, to input in QGeoCoordinate, because class QGeoCoordinate only accept double value

here's is what i mean :

new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPo int),m_markerOffset,m_markerIcon)
latPoint and longPoint must be declared as double..

but, i need all of value digits (12digits) from database to get position more accurately,
because if i use only 6digits's value, the position not shown accurately...

what should i do to get 12digits value of double from database??

nix
11th July 2011, 08:34
Hi,

Please give more information about your problem.

How did you now that the value in your database is the correct value (12 digits data)? How did you check that?
Which database are you using?
Which type of data are you using for this field in the database?

Have you try to calculate delta between expected value and the value you got and display something if the result is not 0? Just in the case the displayed value is round somewhere in the process.

I notice you are developing on Symbian have you take in consideration the following part in qt doc to 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.

azuraZelda
11th July 2011, 09:13
hello nix,

>> first, i check it with query select from database, and shown it on QLineEdit with code: latEdit->setText(QString::number(latPOI, 'f', 12));
and the results is shown 12 digits, there's no problem if its going to string type
>> when i create field of latitude and longitude, the type of data is REAL

is there somtehing wrong with my code above?

nix
11th July 2011, 09:37
first, i check it with query select from database, and shown it on QLineEdit with code: latEdit->setText(QString::number(latPOI, 'f', 12));
Ok, it shows that the right value is in the db, very strange.

Try this exact line in the example code you posted and give the result (just to be sure) :

qDebug() << "latPoint = " << queryLat.value(0).toDouble() << "ltsPoint in str = " << QString::number(queryLat.value(0).toDouble(), 'f', 12);
Maybe the conversion goes wrong or the qDebug() is displaying a rounded value, this debug line should give you some answers.
But this is sure : you can't have a 12 digits precision when you are doing the string conversion if you haven't at least a 12 digits precision in your double :D.

azuraZelda
14th July 2011, 12:04
hello nix, its gives me value:


latPoint = 52.5058 ltsPoint in str = "52.505757190000"

is there something wrong with my code or my SDK already?
i have no idea for it..

nix
18th July 2011, 08:06
Hi, nothing to worry about here it's just a joke qDebug function do to you. The double value is correct, but when displayed with qDebug the value is round.

To be sure you can try the following demo code :

#include <QtDebug>
#include <cmath>

int main(int argc, char *argv[])
{
double pi = M_PI;
qDebug() << "Pi is : " << pi << "but pi is : " << QString::number(pi, 'f', 16);
}

and you will get :

Pi is : 3.14159 but pi is : "3.1415926535897931"

Don't worry about that, if you want to display your value with qDebug in 12 digits try :

qDebug("Pi is %.12f", pi)

azuraZelda
21st July 2011, 01:20
hello nix, thnks for reply..

with this code :

qDebug("Pi is %.12f", pi)
its gimme value :

3.1415926535897931

its work on debug, but i still have problem with the code i share before :

new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPo int),m_markerOffset,m_markerIcon)
the problems are :
(latPoint,longPoint) ---> 1. only can be filled with double
2. its cant be filled with string
3. its cant be filled with qdebug value

But i need value of double with 12 precision...
Like i share before, im using database, so i call the value of field with this code :

QSqlQuery queryLat;
qreal latPoint;
i=1
//how to get the real latitude value from database???
queryLat.prepare( "select latPOI from tabPOI where id in (:states)");
queryLat.bindValue(":states", i);
queryLat.exec();
qDebug() << "LATITUDE";
while( queryLat.next() ) {
latPoint = queryLat.value(0).toDouble();
}
new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPo int),m_markerOffset,m_markerIcon)
//conversion with .toDouble() only give me value with 6 precision.....
//is there another way of convertion format??
//like .toDouble(.%12f), maybe??? i dont know, please help me


is there something wrong with my CPUs ARM architectures??

nix
21st July 2011, 07:14
From Qt Doc :

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.

So when you store your double value in a qreal it seems to me you convert it into a float, which can't give you 12 significant digits.

Replace your qreal by double, and it should work.

ChrisW67
21st July 2011, 07:37
Do you really need a latitude or longitude to twelve decimal places? At the twelfth decimal place the difference between adjacent values amounts to 60 pico arc-minutes... about a 100 nanometres on the Earth's surface. Even at the sixth decimal place the distance difference is around 100 millimetres. I ask because forcing an ARM processor to do double mathematics is costly if not truly necessary (which is why Qt avoids it).

azuraZelda
22nd July 2011, 02:29
From Qt Doc :


So when you store your double value in a qreal it seems to me you convert it into a float, which can't give you 12 significant digits.

Replace your qreal by double, and it should work.

i've try it, but still didnt work, a change variable to double, and also field in table database to double,,,
i.ve no idea nix


Do you really need a latitude or longitude to twelve decimal places? At the twelfth decimal place the difference between adjacent values amounts to 60 pico arc-minutes... about a 100 nanometres on the Earth's surface. Even at the sixth decimal place the distance difference is around 100 millimetres. I ask because forcing an ARM processor to do double mathematics is costly if not truly necessary (which is why Qt avoids it).

hey chris, thnks for reply,
yes, i need it, because if my coordinate only use six decimal places, the position in map shown not accurately,,
so there.s a way? how to force it chris??