[SailfishDevel] QT String issue

Martin Kampas martin.kampas at jolla.com
Tue Sep 12 12:39:09 UTC 2017


Hi Dylan,

The backslashes you see in the output are only added when you print the string, not actual characters of the string:

"\"Intex Aqua Fish\""

So what you need is to replace just the doublequotes - try data.replace("\"", "") or better data.remove('"').

BR,
Martin

________________________________
From: Devel [devel-bounces at lists.sailfishos.org] on behalf of Dylan Van Assche via Devel [devel at lists.sailfishos.org]
Sent: Tuesday, September 12, 2017 2:23 PM
To: Sailfish OS Developers mailing list
Subject: Re: [SailfishDevel] QT String issue

Hi Dmitriy,

For some reason, it doesn't work...

QString data = line.split('=', QString::SkipEmptyParts).at(1);

data.replace("\\\"", "");

dataList.append(qMakePair(querry, data));

This is my code now, but the result is still the same for some reason.
I think I do something still wrong :(

Cheers,
Dylan

-------- Original Message --------
Subject: Re: [SailfishDevel] QT String issue
Local Time: 12 September 2017 2:13 PM
UTC Time: 12 September 2017 12:13
From: dylan.van.assche at protonmail.com
To: Sailfish OS Developers mailing list <devel at lists.sailfishos.org>

Hi Dmitriy,

Thanks for the information! I just started to learn QT C++ :)

Cheers,
Dylan



-------- Original Message --------
Subject: Re: [SailfishDevel] QT String issue
Local Time: 12 September 2017 12:41 PM
UTC Time: 12 September 2017 10:41
From: dpurgin at gmail.com
To: Dylan Van Assche <dylan.van.assche at protonmail.com>, Sailfish OS Developers <devel at lists.sailfishos.org>

Hi Dylan,
trimmed() removes whitespaces only. You need to replace \" with an empty string and "escape" both \ and ". You need escaping because this is how string literals in C/C++ work. Try calling str.replace("\\\"", ""), where str an object of QString.

Also note that trimmed() is a const method and does not change the object for which it was called. I.e.

QString str1 = "  a  ";
str1.trimmed();
// str1 is unchanged but returns a QString object which is "a"

Cheers
Dmitriy


On Tue, Sep 12, 2017 at 12:25 PM, Dylan Van Assche via Devel <devel at lists.sailfishos.org<redir.aspx?REF=hSOZmXePy6vw3rU4NUCBUwLqgjh9Mo0neXylsazEc6WCX10P2vnUCAFtYWlsdG86ZGV2ZWxAbGlzdHMuc2FpbGZpc2hvcy5vcmc.>> wrote:
Hi,

I'm reading the sfos-release and the hw-release file in /etc from C++ but for some lines I get this in my strings as output:




"\"Intex Aqua Fish\""

I tried trimmed() and remove() but I can't figure out how to clean it correctly. The \" characters are annoying.

Kind regards,
Dylan Van Assche


_______________________________________________
SailfishOS.org Devel mailing list
To unsubscribe, please send a mail to devel-unsubscribe at lists.sailfishos.org<redir.aspx?REF=8vYPlC46P7_sdO41Gm9TecKuKsnmL9m4tfz011wxDyj8wF8P2vnUCAFtYWlsdG86ZGV2ZWwtdW5zdWJzY3JpYmVAbGlzdHMuc2FpbGZpc2hvcy5vcmc.>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.sailfishos.org/pipermail/devel/attachments/20170912/503955a9/attachment-0001.html>


More information about the Devel mailing list