That's a simple question with an insanely complicated answer.
A few guidelines:
1. I advise against putting non-ASCII characters in source code. The
behavior is compiler-dependent. In Wt, use an external XML file to
store those strings, and use
WApplication::messageResourceBundle().use("..."); to load them. In
your code, construct your internationalized WString using keys and tr:
new WPushButton(tr("ok"), this);. Added benefit is that your
application will be internationalized.
2. If you really want to write special characters in your source files
(knowing that it is a bad idea), you have a few options:
// Usually works, as long as you save your .cpp file in the right
encoding for your platform: construct a WString from a wstring
WString(L"á,à,ã,é,ê,ü,ç");
// Usually works on Linux, not on Windows. Assumes that your compiler
and input file use UTF-8 encoding
WString(fromUTF8("á,à,ã,é,ê,ü,ç"));
// Interpret the string in the character encoding of the locale of
the environment in which your application runs. If you run a
portuguese Windows, your app will work, but if you install it on an
english Windows, your app will no longer work. It helps to specify a
locale explicitly between the quotes.
WString("á,à,ã,é,ê,ü,ç", std::locale(""));
// Will not work for non-ASCII characters: the string is interpreted
in the global C+ locale (by default the "C" locale, which only works
fine for ASCII characters):
WString("á,à,ã,é,ê,ü,ç");
// Unless you modify your global locale first (again, depends on how
your OS's environment was configured!):
// std::locale(): a copy of the global locale
// std::locale(""): construct a locale from the environment's LANG and
LC_* variables
// We set the global locale to a locale that is a copy of the current
global locale,
// but where the 'collate' and 'ctype' facets are copied from the
environment's locale.
// These facets contain the character
encoding/conversion/comparison/... aspects.
std::locale::global(std::locale(std::locale(), std::locale(""),
std::locale::collate | std::locale::ctype));
Bottom line: if constructing a WString from a std::string (or char *),
you have to tell Wt how that string was encoded. The default in C++,
the "C" locale, is generally not useful for anything but ASCII
characters.
I recently wrote a whole encoding-related story as answer to a bug report:
http://redmine.webtoolkit.eu/issues/555
BR,
Wim.
2010/11/1 John Robson <[email protected]>:
> I'm doing my first page by changing the example Hello.
>
> When I use accented characters (á,à,ã,é,ê,ü,ç), page compiles fine but
> does not appear in the browser and in the terminal I get this error:
> "invalid numeric character entity"
>
> What can I do to write texts in Portuguese (which has accents)?
>
>
> ------------------------------------------------------------------------------
> Nokia and AT&T present the 2010 Calling All Innovators-North America contest
> Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
> $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
> Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
> http://p.sf.net/sfu/nokia-dev2dev
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest
>
------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest