Hello,

WString will by default interpret a string passed at construction as being
encoded in the currently active C++ locale. By default, this is the C
locale, which is not UTF8.

Writing UTF8 in C++ source code is non-portable, but if you stick to Linux
and gcc, it works. You need to tell WString that the proper encoding of the
string is not ASCII, but rather UTF8. You can do this in a number of ways:

1. use the static function WString::fromUTF8("hëllò");
2. use the WString constructor WString("héllö", UTF8);
3. use the WString constructor passing an appropriate std::locale object as
second parameter
4. use the WString constructor with wide string characters:
WString(L"héllö"). At runtime a UTF-32 (on linux) to UTF-8 recoding will
take place
5. change your default C++ locale to a UTF-8 locale:
std::locale::global(std::locale("en_US.UTF-8"));

Watch out modifying the global locale, make sure that you only change the
character encoding and not e.g. the number formatting etc, since Wt uses
the default C++ locale for generating some number strings too. Note that
the en_US.UTF-8 string is not portable and dependent on the system too.

We use and recommend method (1).

I hoped that with C++11, you'd be allowed to write WString(u8"hëllò").
Unfortunately, there's no specific type for utf8 in C++11, so the normal
char-typed constructor for WString would be called and we'd still be in the
dark on the character encoding. Similar to the curren option with L"...",
we will be able to recognise WString(u"hello") and WString(U"hello"), but
then we need a runtime recoding of UTF-16 or UTF-32 to UTF-8, which is
silly for constant strings.

BR,
Wim.


2013/10/13 Muhammad Nasser Al-Noimi <mnno...@gmail.com>

>  Hi,
>
> I'm using Wt with Qt Creator, I got "??" for every non ANSI char althoughthe
> character encoding for the resulted page is UTF-8. I'm wondering if the
> problem is compiler related or Wt.
>
>
>    - Local strings works good for standard Qt application.
>     - I want to write local strings inside the application not using the
>    Wt style multi-language support (XHTML).
>
> Thanks
>
>
> ------------------------------------------------------------------------------
> October Webinars: Code for Performance
> Free Intel webinars can help you accelerate application performance.
> Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most
> from
> the latest Intel processors and coprocessors. See abstracts and register >
> http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
> _______________________________________________
> witty-interest mailing list
> witty-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
>
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
witty-interest mailing list
witty-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to