[Qt-interest] Fwd: Convert a QString to string

Thiago Macieira thiago.macieira at trolltech.com
Tue Feb 10 22:12:08 CET 2009


ami guru wrote:
>Hello Thiago,
>
>
>What  if we are using some third party API that uses the std::string
> instad of the std::wstring
>
>
>The third party API has function that accept string instead
>
>
>Any suggestion on that?

Yes: convince the third-party API to use QString too, since it's superior 
in most aspects.

But, in case you can't...

Just like when using const char * or QByteArray, you need to know which 
encoding the string must be. That's why I said std::string is a byte 
array, not a string.

So, if you want to use std::string, you must choose the encoding 
correctly. You probably need to do the conversion in two steps and start 
with converting to QByteArray (under the correct encoding), then convert 
to std::string manually.

-- 
Thiago Macieira - thiago.macieira (AT) nokia.com
  Senior Product Manager - Nokia, Qt Software
      Sandakerveien 116, NO-0402 Oslo, Norway
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090210/620b546a/attachment.bin 


More information about the Qt-interest-old mailing list