One thing I 'd like to point out is that we should avoid local character
encoding at ALL costs.  the correct way to do this kind of stuff is with
Unicode.  If you need a classic C-string then use UTF-8, its compatible
with 8-byte characters and won't break internationalization.

So please, please, please use: QString::toUtf8() and keep
internationalization in mind.

-John

> Hi guys,
>
> I had to convert a QString to a char* string a few days ago, and after
> looking it up, I realized that it's not terribly obvious how to do it
> properly, and it's very easy to do it incorrectly.
>
> Correct way:
>
>     QByteArray ba = your_qstring.toLatin1();
>     const char *c_str = ba.data();
>
> Incorrect way:
>
>     const char* c_str = your_qstring.toLatin1().data();
>
> In the incorrect way, the QByteArray hasn't been stored and no longer
> exists after the .toLatin1() call (your c_str pointer is bad).
> See:
> http://trolltech.com/developer/knowledgebase/faq.2007-01-30.9032238253/
>
> I grepped through the code and found some suspicious usage:
>
> $ grep "\.data" src/*.cpp
> src/configobject.cpp:           cm_writemsg_utf8(5,
> strconf.toUtf8().data());
> src/herculeslinuxlegacy.cpp:        qDebug("  %d. kqHerculesValidPrefix[i]
> = [%s]",i, kqHerculesValidPrefix[i].data());
> src/xmlparse.cpp:            s = node2.toCDATASection().data();
> src/xmlparse.cpp:            s = node2.toCDATASection().data();
>
> Super easy mistake to make, so just keep an eye out for this sort of
> thing. I've committed fixes for the above, so hopefully that'll fix the
> odd quirk.
>
> Thanks,
> Albert
>
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> _______________________________________________
> Mixxx-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/mixxx-devel
>



-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Mixxx-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to