Format string Qt html charset

Asked

Viewed 72 times

2

I have the following string: Qstring str = "Macarr & # x and 3 ; the integral. < br/>" (I put space between all characters of the special character if it would not be visible and would appear the A with the uncle "is")

and I wanted to format it so it would come out like this: Qstring str = "Integral noodles. Integral car. n"

I don’t know the formatting/charset of this string, but I wanted to be able to take and transform all its special characters the "ã" of the first word noodle " & # x and 3 ; " and leave them correctly and if possible also exchange all the html tags (in this case < br/>) for an n, for example...

how can I do this?

1 answer

2

There is no specific method in Qt to decode entities, but an outline is to use

QTextDocument *texto= new QTextDocument();
texto->setHtml( "Macarr&#xe3;o integral<br>" );

and take "converted" with

texto->getPlainText();
  • I used the function toPlainText(); but I kept the character in hexa and other parts of the string that (not the example above) had characters "ã, ù and etc." were changed... but thanks anyway, already gave me a direction to research.

  • @Evandro Check if you are working with Qt in the same encoding of your text, otherwise the result is unpredictable.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.