Results 1 to 5 of 5

Thread: Converting QGeoCoordinate to a string and the splitting values to another list

  1. #1
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default Converting QGeoCoordinate to a string and the splitting values to another list

    I have a QGeoCoordinate named newPosDeg. While debugging, the Locals and Expressions window shows the following value(s) for the variable

    Locals and Expressions
    this
    newPosDeg @0x19b9918c QGeoCoordinate
    d @0x19b9918c QSharedDataPointer<QGeoCoordinatePrivate>
    [QSharedData] ref: 1 QSharedData
    alt 90.0 double
    lat 35.2371746642 double
    lng -118.002151755 double


    These are the values expected. However, when I attempt to split this QGeoCoordinate using the QGeoCoordinate::CoordinateFormat of DegreesMinutesSecondsWithHemisphere to a StringList called posList with the command...

    Qt Code:
    1. QStringList posList = newPosDeg.toString(degFormat).split(',');
    To copy to clipboard, switch view to plain text mode 
    the value of posList in the Locals and Expressions window is as follows...

    posList
    [0] "35° 14' 13.8" N"
    [1] " 118° 0' 7.7" W"
    [2] " 90m"


    Note the space prepended in front of the value for elements 1 and 2, and not element 0.
    Does anyone know if this is the standard behavior for the split function used in this manner?

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    503
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Converting QGeoCoordinate to a string and the splitting values to another list

    Hi, that space has always been there because QGeoCoordinate::toString generates a string like this: "27° 28' 3.2" S, 153° 1' 40.4" E, 28.1m", and splitting does not remove anything except the separator character/string.
    You could split with ", " (string with comma followed by space) instead of ','.

    Ginsengelf

  3. The following user says thank you to Ginsengelf for this useful post:

    Corny (14th May 2019)

  4. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Converting QGeoCoordinate to a string and the splitting values to another list

    You could split with ", " (string with comma followed by space) instead of ','.
    In which case I think you'd need to turn off the KeepEmptyParts option to split(). The combination of "," and " " consecutively would generate an empty string in the list, I think.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. The following user says thank you to d_stranz for this useful post:

    Corny (16th May 2019)

  6. #4
    Join Date
    Nov 2016
    Location
    Ridgecrest California
    Posts
    33
    Thanks
    11
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Thumbs up Re: Converting QGeoCoordinate to a string and the splitting values to another list

    Thanks d_stranz for helping. You stated...

    In which case I think you'd need to turn off the KeepEmptyParts option to split(). The combination of "," and " " consecutively would generate an empty string in the list
    When I first tried it, I was thinking the same thing, however it turns out that I didn't need to change the behavior. The documentation states...

    If behavior is QString::SkipEmptyParts, empty entries don't appear in the result. By default, empty entries are kept.

    so it worked just great with the default behavior.

    Thanks again.

  7. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Converting QGeoCoordinate to a string and the splitting values to another list

    I'm not in front of a PC with Qt on it, so I wasn't sure whether Keep or Skip was the default. It's something to keep in mind though when using split().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. How to convert string hex values to its real binary values?
    By AttilaPethe in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2012, 23:47
  2. Replies: 1
    Last Post: 23rd April 2011, 18:33
  3. [perl] converting a string
    By mickey in forum General Programming
    Replies: 5
    Last Post: 26th March 2009, 14:33
  4. Retrieving and converting values
    By jcoop in forum Newbie
    Replies: 3
    Last Post: 19th February 2009, 09:01
  5. Converting number to string.
    By safknw in forum Newbie
    Replies: 2
    Last Post: 18th September 2006, 13:12

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.