Results 1 to 12 of 12

Thread: qsqlquery problem, i cant get my real value from database, please help...

  1. #1
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Exclamation qsqlquery problem, i cant get my real value from database, please help...

    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:


    Qt Code:
    1. QSqlQuery queryLat;
    2. qreal latPoint;
    3. i=1
    4.  
    5. //how to get the real latitude value from database???
    6. queryLat.prepare( "select latPOI from tabPOI where id in (:states)");
    7. queryLat.bindValue(":states", i);
    8. queryLat.exec();
    9. qDebug() << "LATITUDE";
    10. while( queryLat.next() ) {
    11. latPoint = queryLat.value(0).toDouble();
    12. qDebug() << "latPoint = " << latPoint;
    13. }
    14. qDebug() << "LATITUDE";
    To copy to clipboard, switch view to plain text mode 



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

    Qt Code:
    1. latPoint = 52.7849
    To copy to clipboard, switch view to plain text mode 

    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...
    Last edited by azuraZelda; 11th July 2011 at 07:55.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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).
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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 :
    Qt Code:
    1. new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPoint),m_markerOffset,m_markerIcon)
    To copy to clipboard, switch view to plain text mode 
    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??

  4. #4
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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.

  5. #5
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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?

  6. #6
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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) :
    Qt Code:
    1. qDebug() << "latPoint = " << queryLat.value(0).toDouble() << "ltsPoint in str = " << QString::number(queryLat.value(0).toDouble(), 'f', 12);
    To copy to clipboard, switch view to plain text mode 
    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 .

  7. #7
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    hello nix, its gives me value:

    Qt Code:
    1. latPoint = 52.5058 ltsPoint in str = "52.505757190000"
    To copy to clipboard, switch view to plain text mode 

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

  8. #8
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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 :
    Qt Code:
    1. #include <QtDebug>
    2. #include <cmath>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. double pi = M_PI;
    7. qDebug() << "Pi is : " << pi << "but pi is : " << QString::number(pi, 'f', 16);
    8. }
    To copy to clipboard, switch view to plain text mode 

    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 :
    Qt Code:
    1. qDebug("Pi is %.12f", pi)
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    hello nix, thnks for reply..

    with this code :
    Qt Code:
    1. qDebug("Pi is %.12f", pi)
    To copy to clipboard, switch view to plain text mode 
    its gimme value :
    Qt Code:
    1. 3.1415926535897931
    To copy to clipboard, switch view to plain text mode 

    its work on debug, but i still have problem with the code i share before :
    Qt Code:
    1. new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPoint),m_markerOffset,m_markerIcon)
    To copy to clipboard, switch view to plain text mode 
    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 :
    Qt Code:
    1. QSqlQuery queryLat;
    2. qreal latPoint;
    3. i=1
    4. //how to get the real latitude value from database???
    5. queryLat.prepare( "select latPOI from tabPOI where id in (:states)");
    6. queryLat.bindValue(":states", i);
    7. queryLat.exec();
    8. qDebug() << "LATITUDE";
    9. while( queryLat.next() ) {
    10. latPoint = queryLat.value(0).toDouble();
    11. }
    12. new QGeoMapPixmapObject(QGeoCoordinate(latPoint,longPoint),m_markerOffset,m_markerIcon)
    13. //conversion with .toDouble() only give me value with 6 precision.....
    14. //is there another way of convertion format??
    15. //like .toDouble(.%12f), maybe??? i dont know, please help me
    To copy to clipboard, switch view to plain text mode 


    is there something wrong with my CPUs ARM architectures??

  10. #10
    Join Date
    Dec 2008
    Location
    France
    Posts
    93
    Thanked 23 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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.

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    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).

  12. #12
    Join Date
    Jul 2011
    Location
    Indonesia
    Posts
    6
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: qsqlquery problem, i cant get my real value from database, please help...

    Quote Originally Posted by nix View Post
    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

    Quote Originally Posted by ChrisW67 View Post
    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??

Similar Threads

  1. [QSqlQuery] Problem with not open database
    By xkazielx in forum Newbie
    Replies: 11
    Last Post: 1st September 2013, 20:32
  2. Replies: 1
    Last Post: 3rd July 2011, 10:41
  3. Replies: 1
    Last Post: 17th January 2010, 07:36
  4. QSqlQuery::exec: database not open
    By newtowindows in forum Qt Programming
    Replies: 8
    Last Post: 29th October 2009, 08:48
  5. Database and QSqlQuery::prepare problem
    By fengtian.we in forum Qt Programming
    Replies: 1
    Last Post: 31st October 2007, 23:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.