Project

General

Profile

Handling special characters in WString

Added by Alan Finley over 11 years ago

I get a QString from a database, then convert it to a WString and set to a widget:

QString str = ...

Wt::WString text = Wt::WString::fromUTF8(str.toUtf8().data());

Wt::WText *textWidget = new Wt::WText;
textWidget->setTextFormat(Wt::PlainText);
textWidget->setText(text);

If a string from database contains some special characters (for exmaple 'square' symbol), my page doesn't load and I get a popup "Wt internal error: SyntaxError".

How do I handle special non-printable characters in WString?


Replies (2)

RE: Handling special characters in WString - Added by Alan Finley over 11 years ago

Alan Finley wrote:

for exmaple 'square' symbol

Sorry, it's not the 'square' symbol causes that problem. It's some character of QChar::Separator_Line category. But I have no idea what it is.

RE: Handling special characters in WString - Added by Wim Dumon over 11 years ago

Can reproduce this with the following change to the hello example:

greeting_->setText(WString::fromUTF8("Hello there,\xE2\x80\xA8 ", true) + nameEdit_->text());

Learning every day. Line separator characters (which may not occur in string literals) in JS are:

\u000A Line Feed <LF>
\u000D Carriage Return <CR>
\u2028 Line separator <LS>
\u2029 Paragraph separator <PS>

Wt escapes and , but not or . That should be considered a bug, since it will cause parse errors in the browser.

I created #1996 for you.

BR,

Wim.

    (1-2/2)