A little question about QTextBrowser
-
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] -
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? -
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] -
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] -
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" />)
-
[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. -
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]