convert accented characters from unicode at UTF-8
-
Hello,
I need read from db access and write text UTF-8.I have this code for present string into html/webengine after read data .
QString resultString = TextToHTML(strValue);
But result si always this.
Where am I wrong?
Of course, I also accept advice not to use an old-fashioned function.
I tried to figure out QTextCodec but couldn't apply it for my purpose.In the Access db I see exactly like this
Thanks for your answer.
-
What exactly is your problem? And please don't post screenshots but code.
-
What exactly is your problem? And please don't post screenshots but code.
@Christian-Ehrlicher My problem
I have this char "à" and it is view so :�
-
@Christian-Ehrlicher My problem
I have this char "à" and it is view so :�
@elicat said in convert accented characters from unicode at UTF-8:
My problem
I have this char "à" and it is view so :
�Are you sure you are reading the string correctly from DB?
And why you do not useQString::toHtmlEscaped()
to convert your UTF8 string into HTML escape sequence? -
@elicat said in convert accented characters from unicode at UTF-8:
My problem
I have this char "à" and it is view so :
�Are you sure you are reading the string correctly from DB?
And why you do not useQString::toHtmlEscaped()
to convert your UTF8 string into HTML escape sequence?@KroMignon I have try
QString::toHtmlEscaped()
But not have difference "à" stay "à" and in html I see
�
-
Apart from @KroMignon comment about to/fromHtmlEscaped() you have to make sure that your compiler treats your source as utf-8. MSVC is a little bit stupid with this so try to create your non-latin characters with a unicode sequence (e.g. \ue8 for è) or from a QChar.
-
@KroMignon I have try
QString::toHtmlEscaped()
But not have difference "à" stay "à" and in html I see
�
@elicat said in convert accented characters from unicode at UTF-8:
I have try
QString::toHtmlEscaped()But not have difference "à" stay "à" and in html I see
�I don't really understand your issue.
Do you want to generate an HTML page?
Why not simply force html page to UTF-8, so the web browser could read it.
Simply add<meta charset="utf-8"/>
in the HEAD section. -
Since you are using accents in source code and expect them to be UTF-8, you should make sure that they are actually UTF-8.
- Make sure your source code file is actually saved as UTF-8. In Qt Creator go to 'Edit' -> 'Select Encoding'. In the dialog the current encoding is highlighted. If it is not already UTF-8, select UTF-8 and choose 'Save with encoding'.
- Make sure everything is compiled as UTF-8. This almost exclusively applies to Windows/MSVC. Microsoft's compiler has two places IIRC to set UTF-8: once for the source code and once for the compiled code.
You can try to print a character on standard output as well. On Windows (and only on Windows, so put a
#ifdef
around it) we usesetlocale(LC_ALL, ".UTF8");
at the beginning ofmain
to have input/output as UTF-8 as well. -
@elicat said in convert accented characters from unicode at UTF-8:
I have try
QString::toHtmlEscaped()But not have difference "à" stay "à" and in html I see
�I don't really understand your issue.
Do you want to generate an HTML page?
Why not simply force html page to UTF-8, so the web browser could read it.
Simply add<meta charset="utf-8"/>
in the HEAD section.@KroMignon hello, my project is QT/QML/QtWebengine with Db Access.
IN my Html head I have already<meta charset="utf-8"/>
This is a problem. I read "à" from Database but into html is present �
-
@KroMignon hello, my project is QT/QML/QtWebengine with Db Access.
IN my Html head I have already<meta charset="utf-8"/>
This is a problem. I read "à" from Database but into html is present �
@elicat said in convert accented characters from unicode at UTF-8:
This is a problem. I read "à" from Database but into html is present �
You read
à
from DB, but with which code page?
Are you sure, it is UTF-8 and not Windows-1252 for example?[EDIT]
Can you show how you read this string from DB? -
@elicat said in convert accented characters from unicode at UTF-8:
This is a problem. I read "à" from Database but into html is present �
You read
à
from DB, but with which code page?
Are you sure, it is UTF-8 and not Windows-1252 for example?[EDIT]
Can you show how you read this string from DB?@KroMignon said in convert accented characters from unicode at UTF-8:
Windows-1252
No, the text in DB "à" when write into html is �.
if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct -
@KroMignon said in convert accented characters from unicode at UTF-8:
Windows-1252
No, the text in DB "à" when write into html is �.
if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct@elicat said in convert accented characters from unicode at UTF-8:
No, the text in DB "à" when write into html is �.
if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correctObviously your are doing something wrong somewhere.
There are not so many possibilities:- the string is not read correctly from DB
- the string is not written correctly to output file. How do you write the string into to file?
I create a HTML export some days ago, which use UTF-8 chartset and it works fine.
Without showing how you have done it, it is not possible to help you more. -
@KroMignon said in convert accented characters from unicode at UTF-8:
Windows-1252
No, the text in DB "à" when write into html is �.
if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correct@elicat, no idea what your problem is BUT I saw this question mark in rotated rectangle in visual studio text editor for some Arabic diacritical marks (similar to yours) and asked about it in Microsoft's QA forum and they told it's because the keyboard layout I'm using uses 8 bit charset.
Is UTF-8 equivalent to 8 bit charset? If so, change that and see whether it solves the issue.
-
@elicat said in convert accented characters from unicode at UTF-8:
No, the text in DB "à" when write into html is �.
if I saved "à" in the HTML with the meta charset set to UFT-8 it would be correctObviously your are doing something wrong somewhere.
There are not so many possibilities:- the string is not read correctly from DB
- the string is not written correctly to output file. How do you write the string into to file?
I create a HTML export some days ago, which use UTF-8 chartset and it works fine.
Without showing how you have done it, it is not possible to help you more.@KroMignon said in convert accented characters from unicode at UTF-8:
ring is not written correctly to output file. How do you write the string into to file?
I read from file db Acces width class QSqlQuery, for example :
QSqlQuery qSqlQueryObject; QString valueField = qSqlQueryObject.value(fieldname).toString();
After I write file HTML.
So i vae found "error". Was Missing set codec :QTextStream pageStream(&file); pageStream.setCodec("UTF-8");
-
@KroMignon said in convert accented characters from unicode at UTF-8:
ring is not written correctly to output file. How do you write the string into to file?
I read from file db Acces width class QSqlQuery, for example :
QSqlQuery qSqlQueryObject; QString valueField = qSqlQueryObject.value(fieldname).toString();
After I write file HTML.
So i vae found "error". Was Missing set codec :QTextStream pageStream(&file); pageStream.setCodec("UTF-8");
-
@elicat
I SOLVED !!!! Thank you all.I read weel but when I save text into file HTML I didn't set the codec
QTextStream pageStream(&file); pageStream.setCodec("UTF-8");
@elicat said in convert accented characters from unicode at UTF-8:
SOLVED
Great! so please don't forget to mark your post as solved then.
-
@elicat
I SOLVED !!!! Thank you all.I read weel but when I save text into file HTML I didn't set the codec
QTextStream pageStream(&file); pageStream.setCodec("UTF-8");