A little question about QTextBrowser



  • 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.



  • Try with
    @helpReader->setSource((QUrl(":/help/index.htm")));@

    EDIT :

    Also, pass parent.
    @ QTextBrowser *helpReader = new QTextBrowser(this);@



  • 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]



  • the above code works for me. there must be some thing wrong with your qrc path..

    try
    @helpReader->setSource((QUrl(":help/index.htm")));@



  • 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]



  • 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".



  • 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]



  • Do post if you fix it, am really curious..


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.