[Interest] Converting std::string.c_str() code to use QString methods

Scott Aron Bloom scott.bloom at onshorecs.com
Fri Aug 30 21:17:58 CEST 2013


I use toUtf8()... Though it wouldn't surprise me if Thiago scolds me for it :)

Note, If you are using a variatic function (printf), you need to use toUtf8().data()

toUtf() returns a QbyteArray which has a conversion operator to char *... 

Scott

-----Original Message-----
From: interest-bounces+scott.bloom=onshorecs.com at qt-project.org [mailto:interest-bounces+scott.bloom=onshorecs.com at qt-project.org] On Behalf Of Michael Jackson
Sent: Friday, August 30, 2013 12:09 PM
To: interest at qt-project.org
Subject: [Interest] Converting std::string.c_str() code to use QString methods

I have a large code base that we are migrating to more fully utilize Qt classes. Many places in the code have lines like the following:

std::string path("/path/to/foo.txt");
FILE* f = fopen(path.c_str(), "wb");

If the "path" variable is now declared as a QString which QString method would be me the equivalent as the "c_str()" of std::string?

Not sure if I should be using "toASCII()" or "data()" or "toUtf8()" or what exactly.

Google didn't really give me a definitive answer.

Many Thanks
--
Mike Jackson
imikejackson & gmail * com

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest



More information about the Interest mailing list