PDA

View Full Version : QWebView doesn't display correctly unicode



binaural
30th August 2010, 16:21
I have a compiled qt embedded 4.6.2 .for arm successfully and try to run simple browser:


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebView *view = new QWebView();

view->load(QUrl("/home/index.html"));
view->showFullScreen();

return a.exec();
}


I have a problem with displaying some of the unicode characters in webpages. I'm from Slovakia and we have some special characters. In my case e.g. character ľ isn't display correctly (just blank space instead). I compile qt with unicode font but it doesn't help. How can I make my web browser display correctly webpages?

Thanks,

Marek

wysota
30th August 2010, 16:33
Did you set the proper html encoding tags in the file?

binaural
30th August 2010, 16:35
Same webpage test on qt on desktop and it display correctly all characters.

wysota
30th August 2010, 17:18
Same webpage test on qt on desktop and it display correctly all characters.

Which means exactly nothing... The default encoding might be different or fonts may not contain proper glyphs on your embedded platform. Check the file encoding, html encoding and check whether the font can display those characters at all (i.e. by placing them on a regular QLabel).

binaural
31st August 2010, 07:59
Hi,

you're right if I just use Qlabel label("ščťž") on desktop it doesn't display correctly in QLabel.
I use following code and it display correctly on desktop but not on embedded device (just empty window):


#include <QtGui/QApplication>
#include <QLabel>
#include <QTextCodec>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QByteArray encodedString = "ščťž";
QTextCodec *codec = QTextCodec::codecForName("utf-8");
QString string = codec->toUnicode(encodedString);

QLabel *view = new QLabel();
view->setText(string);

view->show();
return a.exec();
}


I try to look to docu for qwebview and found followig method:

view->settings()->setDefaultTextEncoding("utf-8");

but have still same result (no correct output). My webpages are utf-8 encoded.Any other options to check?

Thanks in advance,

Marek

wysota
1st September 2010, 19:23
Try:

#include <QtGui>

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QLabel view;
view.setText(QString::fromUtf8("ščťž"));

view.show();
return a.exec();
}

binaural
2nd September 2010, 11:31
wysota: trying your code but no change (no unicode displayed on display) just empty label.

binaural
2nd September 2010, 12:17
Also try:

QString str;
const char * web = "<html><head><title>ľščťžýáÃ*éäúô!! !</title><meta http-equiv=Content-Type content=\"text/html; charset=UTF-8\"></head><body bgcolor='blue'><center><H1>ľščťžýáÃ*éäúô</H1></center><hr>При доступе к сайту произошла ошибка. Пожалуйста проверьте ваше подключение к интернету.</body></html>";
view->setHtml(QString::fromLocal8Bit(web, strlen(web)));

but in window see only chars: ýáÃ*éäúô and also no russian characters only 2 dots(.) Is there possibility that ľščťž aren't in any font for embedded? How can I check that?

Thanks

wysota
2nd September 2010, 12:35
wysota: trying your code but no change (no unicode displayed on display) just empty label.
Are you sure the file is utf-8 encoded? Maybe it's iso-8859-2 encoded?

binaural
2nd September 2010, 13:02
well when open and read by python there are utf-8 encoded characters:
<html>\n<head><title>\xc4\xbe\xc5\xa1\xc4\x8d\xc5\xa5\xc5\xbe\xc3\xbd\x c3\xa1\xc3\xad\xc3\xa9\xc3\xa4\xc3\xba\xc3\xb4!!!</title>\n<meta http-equiv=Content-Type content=text/html; charset=UTF-8>\n</head>\n<body bgcolor='blue'>\n<center><H1>\xc4\xbe\xc5\xa1\xc4\x8d\xc5\xa5\xc5\xbe\xc3\xbd\x c3\xa1\xc3\xad\xc3\xa9\xc3\xa4\xc3\xba\xc3\xb4</H1></center>\n<hr>\xd0\x9f\xd1\x80\xd0\xb8 \xd0\xb4\xd0\xbe\xd1\x81\xd1\x82\xd1\x83\xd0\xbf\x d0\xb5 \xd0\xba \xd1\x81\xd0\xb0\xd0\xb9\xd1\x82\xd1\x83 \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb8\xd0\xb7\xd0\xbe\x d1\x88\xd0\xbb\xd0\xb0 \xd0\xbe\xd1\x88\xd0\xb8\xd0\xb1\xd0\xba\xd0\xb0. \xd0\x9f\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd1\x83\x d0\xb9\xd1\x81\xd1\x82\xd0\xb0 \xd0\xbf\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb5\xd1\x80\x d1\x8c\xd1\x82\xd0\xb5 \xd0\xb2\xd0\xb0\xd1\x88\xd0\xb5 \xd0\xbf\xd0\xbe\xd0\xb4\xd0\xba\xd0\xbb\xd1\x8e\x d1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xba \xd0\xb8\xd0\xbd\xd1\x82\xd0\xb5\xd1\x80\xd0\xbd\x d0\xb5\xd1\x82\xd1\x83.\n</body>\n</html>

so encoding should be correct.

wysota
2nd September 2010, 13:29
I meant the file from my example. Besides I can't really see the utf-8 encoding among this garbage :)

binaural
2nd September 2010, 13:42
What file you mean from your example?
OK start from beginning:
I create a file index.html with utf-8 encoding and also save file as utf-8:


<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<h1>ľščťžýáÃ*</h1>
</body>
</html>



The use this code to display content (web is filename):



QTextStream in(&web);
in.setCodec("utf8");
view->setHtml(in.readAll(), QUrl("file:///home/www/"));


but on display I can see only ýáÃ*.

wysota
2nd September 2010, 15:08
What file you mean from your example?
The one with the label code. I suggest you start with getting that to work.

binaural
3rd September 2010, 06:59
Well problem found. Problem was in font type. It seems unicode font doesn't support special characters. After enabling freetype text is correctly displayed.

wysota
3rd September 2010, 07:44
It seems unicode font doesn't support special characters. After enabling freetype text is correctly displayed.
Aren't you mixing two terms here? "Unicode font" is not about font format, it's about font encoding. Freetype fonts are "unicode fonts" too.

binaural
3rd September 2010, 08:17
Yes maybe I wasn't precise. I was playing with fonts and if I don't compile freetype support to qt default font for displaying was family unifont (unifont_160_50.qpf). After installing truetype default font became (Dejavu Sans) which could correctly display all character which I need. I would say that unifont doesn't contain all special character.

With Dejavu Sans font text is correctly displayed but default font weight is bigger like for unifont and items are shifted. I try to change font weight by:


QFont web_font("DejaVu Sans", 6);

qDebug() << font.weight() << " " << font.pointSize();

web_font.setPointSize(6);
web_font.setWeight(20);
view->setFont(web_font);



but there's no effect (text has same weight and size). Is there any option which I'm missing to set?

Thanks

wysota
3rd September 2010, 08:24
.qpf fonts are bitmap fonts. But you can generate your own .qpf from a font of your choice so I guess you can make one from DejaVu Sans and have proper glyphs available in .qpf.