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

Paul Miller stelefx at gmail.com
Fri Aug 30 21:39:31 CEST 2013


On 8/30/13 2:08 PM, Michael Jackson wrote:
> 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.

Like Scott I use toUf8() when I need to do that (be kind, Thiago!). But 
instead of using FILE * you should prefer a QFile instead if you are able.

I find myself using QtCore more and more to build little command-line 
tools now, at the expense of a 10MB executable.



More information about the Interest mailing list