A little question about QTextBrowser
-
wrote on 6 Sept 2012, 03:30 last edited by
Hi everyone.
I want to use a QTextBrowser to show a help document. But I'm trapped in QTextBrowser. :(@ QTextBrowser *helpReader = new QTextBrowser;@
@ helpReader->setSource((QString("qrc:/help/index.htm")));@the charset of the index.htm is GB2312,and the helpReader shows quite well in my computer.
But When I try to run my program in other's laptop,the helpReader shows a full of strange characters.I was told to use Q3MimeSourceFactory to change the textcodec by calling setExtensionType. But My IDE is Qt 4.7,I can't include the Q3Support Library.
Could any one help me?
Thank you. -
wrote on 6 Sept 2012, 05:17 last edited by
Try with
@helpReader->setSource((QUrl(":/help/index.htm")));@EDIT :
Also, pass parent.
@ QTextBrowser *helpReader = new QTextBrowser(this);@ -
wrote on 6 Sept 2012, 05:24 last edited by
Thank you,sir.
I have a try,but it doesn't work.
Is there a way to change QTextBrowser's character set?
[quote author="Rahul Das" date="1346908658"]Try with
@helpReader->setSource((QUrl(":/help/index.htm")));@[/quote]
-
wrote on 6 Sept 2012, 05:29 last edited by
the above code works for me. there must be some thing wrong with your qrc path..
try
@helpReader->setSource((QUrl(":help/index.htm")));@ -
wrote on 6 Sept 2012, 05:29 last edited by
Besides,if "qrc" is omitted,the program will report a warning like
"QFSFileEngine::open: No file name specified
QTextBrowser: No document for /help/index.htm"Yes,I've passed the parent to the helpReader when it was created.
[quote author="Rahul Das" date="1346908658"]Try with
@helpReader->setSource((QUrl(":/help/index.htm")));@EDIT :
Also, pass parent.
@ QTextBrowser *helpReader = new QTextBrowser(this);@
[/quote] -
wrote on 6 Sept 2012, 05:37 last edited by
Does your HTML file contain an encoding <meta> tag? Also, why choose GB2312 rather than a Unicode encoding like UTF-8/16/32?
Note: For URLs (QUrl) it's "qrc:///path/here", for paths (in QFile for example) it's ":/path/here". -
wrote on 6 Sept 2012, 05:43 last edited by
About character, there was a prev "disc":http://qt-project.org/forums/viewthread/7943
@ QTextBrowser *helpReader = new QTextBrowser(this);
helpReader->setSource(QUrl(":help/index.htm"));@These two lines are enough to show html on the Text Browser.
Have you initialized your qrc file? Are you sure the path is correct?
Or are you trying with a local file, than qrc? -
wrote on 6 Sept 2012, 05:44 last edited by
The HTML contains a few of Chinese characters,requiring charset should be BIG5 or GB2312,like
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
If a unicode encoding (e.g.UTF-8) was used , only to result in a screen of strange characters,which I've tried for many times.
Thank you anyway.[quote author="Terence Simpson" date="1346909878"]Does your HTML file contain an encoding <meta> tag? Also, why choose GB2312 rather than a Unicode encoding like UTF-8/16/32?
Note: For URLs (QUrl) it's "qrc:///path/here", for paths (in QFile for example) it's ":/path/here".[/quote] -
wrote on 6 Sept 2012, 05:51 last edited by
I've no idea that my codes really works on my computer.But when I release the program,and try to open it on other's computer,it suddenly displays a lot of strange contents.
Of course,I put macro
@Q_INIT_RESOURCE()@
in main.cpp,and the path is correct,otherwise I wouldn't open it even on my computer.
Thank you so much.
[quote author="Rahul Das" date="1346910222"]About character, there was a prev "disc":http://qt-project.org/forums/viewthread/7943@ QTextBrowser *helpReader = new QTextBrowser(this);
helpReader->setSource(QUrl(":help/index.htm"));@These two lines are enough to show html on the Text Browser.
Have you initialized your qrc file? Are you sure the path is correct?
Or are you trying with a local file, than qrc?[/quote] -
wrote on 6 Sept 2012, 05:51 last edited by
UTF-8 is perfectly capable of showing Chinese characters: http://en.wikipedia.org/wiki/Chinese_characters (which has a <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />)
-
wrote on 6 Sept 2012, 10:05 last edited by
[quote author="poppw" date="1346910680"]But when I release the program,and try to open it on other's computer,it suddenly displays a lot of strange contents.
[/quote]This is strange! Check with
@ qDebug() << helpReader->toHtml();@
to confirm if char encoding is not changed. -
wrote on 6 Sept 2012, 11:38 last edited by
It seems still of no use.:(
Finally,I give up with QTextBrowser, but in this way
@QDesktopService::openUrl(const QUrl &)@
to call the OS Web Browser to open this html.
Sorry to trouble you many times.[quote author="Rahul Das" date="1346925927"][quote author="poppw" date="1346910680"]But when I release the program,and try to open it on other's computer,it suddenly displays a lot of strange contents.
[/quote]This is strange! Check with
@ qDebug() << helpReader->toHtml();@
to confirm if char encoding is not changed.[/quote] -
wrote on 6 Sept 2012, 12:07 last edited by
Do post if you fix it, am really curious..
5/13