Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QDomElement and QString::toDouble
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QDomElement and QString::toDouble

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mcallegari79
    wrote on last edited by
    #1

    Hi all, I am using Qt 5.2.1
    I found that saving qreal values into an XML tag like this:

    @QPointF pos = getPosition();
    QDomElement tag = doc->createElement("Position");
    tag.setAttribute("xPos", pos.x());
    tag.setAttribute("yPos", pos.y());@

    And then loading them like this:

    @QPointF pos(0, 0);
    pos.setX(tag.attribute("xPos").toDouble());
    pos.setY(tag.attribute("yPos").toDouble());@

    Always returns a 0,0 QPointF.
    I found out the cause is that written values have a "," like these:
    @<Position xPos="4588,235294117647" yPos="921,5686274509804"/>@

    While Qt expects number with a ".", therefore not parsing values correctly.
    Am I missing something or have I just found a bug ?

    If I remember correctly this was working on Qt 4.8.5.

    Thanks

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      What happens when you use this:
      @
      tag.setAttribute("xPos", QString::number(pos.x()));
      tag.setAttribute("yPos", QString::number(pos.y()));
      @

      (Z(:^

      1 Reply Last reply
      0
      • B Offline
        B Offline
        butterface
        wrote on last edited by
        #3

        We had the same problem. Our solution is to change either the locale of your system or the locale for the shell executing your application.
        This might be done directly from the shell or in the properties of QtCreator if you use it.
        We never managed to find a solution which works at any time so far. For some reasons setting the locale via the dedicated c functions does not work.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mcallegari79
          wrote on last edited by
          #4

          [quote author="sierdzio" date="1392767623"]What happens when you use this:
          @
          tag.setAttribute("xPos", QString::number(pos.x()));
          tag.setAttribute("yPos", QString::number(pos.y()));
          @[/quote]

          This seems to be a valid solution. It cuts digits after the decimal points to 2 but if you don't need extreme precision (like in my case) it's ok.

          Thanks sierdzio !

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved