Results 1 to 17 of 17

Thread: QWebView doesn't display correctly unicode

  1. #1
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWebView doesn't display correctly unicode

    I have a compiled qt embedded 4.6.2 .for arm successfully and try to run simple browser:
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4. QWebView *view = new QWebView();
    5.  
    6. view->load(QUrl("/home/index.html"));
    7. view->showFullScreen();
    8.  
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Did you set the proper html encoding tags in the file?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    Same webpage test on qt on desktop and it display correctly all characters.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Quote Originally Posted by binaural View Post
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    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):
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QLabel>
    3. #include <QTextCodec>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8.  
    9. QByteArray encodedString = "ščťž";
    10. QTextCodec *codec = QTextCodec::codecForName("utf-8");
    11. QString string = codec->toUnicode(encodedString);
    12.  
    13. QLabel *view = new QLabel();
    14. view->setText(string);
    15.  
    16. view->show();
    17. return a.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    I try to look to docu for qwebview and found followig method:
    Qt Code:
    1. view->settings()->setDefaultTextEncoding("utf-8");
    To copy to clipboard, switch view to plain text mode 

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

    Thanks in advance,

    Marek

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Try:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6.  
    7. QLabel view;
    8. view.setText(QString::fromUtf8("ščťž"));
    9.  
    10. view.show();
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    wysota: trying your code but no change (no unicode displayed on display) just empty label.

  8. #8
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    Also try:
    Qt Code:
    1. QString str;
    2. 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>";
    3. view->setHtml(QString::fromLocal8Bit(web, strlen(web)));
    To copy to clipboard, switch view to plain text mode 

    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

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Quote Originally Posted by binaural View Post
    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?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    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\xc3\xa1\xc3\xad\xc3\xa9\xc3\xa 4\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\xc3\xa1\xc3\xad\xc3\xa 9\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.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    I meant the file from my example. Besides I can't really see the utf-8 encoding among this garbage
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    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:
    Qt Code:
    1. <html>
    2. <head>
    3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    4. </head>
    5. <body>
    6. <h1>ľščťžýáÃ*</h1>
    7. </body>
    8. </html>
    To copy to clipboard, switch view to plain text mode 

    The use this code to display content (web is filename):
    Qt Code:
    1. QTextStream in(&web);
    2. in.setCodec("utf8");
    3. view->setHtml(in.readAll(), QUrl("file:///home/www/"));
    To copy to clipboard, switch view to plain text mode 

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

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Quote Originally Posted by binaural View Post
    What file you mean from your example?
    The one with the label code. I suggest you start with getting that to work.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #14
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    Well problem found. Problem was in font type. It seems unicode font doesn't support special characters. After enabling freetype text is correctly displayed.

  15. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    Quote Originally Posted by binaural View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #16
    Join Date
    May 2009
    Posts
    55
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebView doesn't display correctly unicode

    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:
    Qt Code:
    1. QFont web_font("DejaVu Sans", 6);
    2.  
    3. qDebug() << font.weight() << " " << font.pointSize();
    4.  
    5. web_font.setPointSize(6);
    6. web_font.setWeight(20);
    7. view->setFont(web_font);
    To copy to clipboard, switch view to plain text mode 

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

    Thanks

  17. #17
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QWebView doesn't display correctly unicode

    .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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 31st August 2011, 16:15
  2. Unicode Font Display Problem
    By QbelcorT in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 2nd September 2009, 06:11
  3. Reg QWebview Display
    By Tavit in forum Qt Programming
    Replies: 0
    Last Post: 5th August 2009, 15:19
  4. Problems to display a QFont in a View/Model correctly
    By NoRulez in forum Qt Programming
    Replies: 0
    Last Post: 8th July 2009, 12:26
  5. QTableView does not display time string correctly
    By ad5xj in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2007, 20:35

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.