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

chandrasekar wagmare sekarwagmare at gmail.com
Wed Feb 11 06:32:30 CET 2009


also ...
QString::toLatin1() returns a QByteArray object. You store a pointer to the
internal data of that temporary object. "const char* str" is a dangling
pointer as soon as the QByteArray object goes out of scope. For more
details, see TT knowledgebase: How can I convert a QString to char* and vice
versa ? <http://trolltech.com/developer/faqs/faq.2007-01-30.9032238253>

On Wed, Feb 11, 2009 at 2:42 AM, Thiago Macieira <
thiago.macieira at trolltech.com> wrote:

> 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
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
>


-- 
CHANDRU
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090211/58ee4648/attachment.html 


More information about the Qt-interest-old mailing list