Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. A little question about QTextBrowser
QtWS25 Last Chance

A little question about QTextBrowser

Scheduled Pinned Locked Moved General and Desktop
13 Posts 3 Posters 8.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    poppw
    wrote on 6 Sept 2012, 03:30 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • R Offline
      R Offline
      Rahul Das
      wrote on 6 Sept 2012, 05:17 last edited by
      #2

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

      EDIT :

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


      Declaration of (Platform) independence.

      1 Reply Last reply
      0
      • P Offline
        P Offline
        poppw
        wrote on 6 Sept 2012, 05:24 last edited by
        #3

        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]

        1 Reply Last reply
        0
        • R Offline
          R Offline
          Rahul Das
          wrote on 6 Sept 2012, 05:29 last edited by
          #4

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

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


          Declaration of (Platform) independence.

          1 Reply Last reply
          0
          • P Offline
            P Offline
            poppw
            wrote on 6 Sept 2012, 05:29 last edited by
            #5

            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]

            1 Reply Last reply
            0
            • T Offline
              T Offline
              twsimpson
              wrote on 6 Sept 2012, 05:37 last edited by
              #6

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

              1 Reply Last reply
              0
              • R Offline
                R Offline
                Rahul Das
                wrote on 6 Sept 2012, 05:43 last edited by
                #7

                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?


                Declaration of (Platform) independence.

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  poppw
                  wrote on 6 Sept 2012, 05:44 last edited by
                  #8

                  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]

                  1 Reply Last reply
                  0
                  • P Offline
                    P Offline
                    poppw
                    wrote on 6 Sept 2012, 05:51 last edited by
                    #9

                    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]

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      twsimpson
                      wrote on 6 Sept 2012, 05:51 last edited by
                      #10

                      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" />)

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        Rahul Das
                        wrote on 6 Sept 2012, 10:05 last edited by
                        #11

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


                        Declaration of (Platform) independence.

                        1 Reply Last reply
                        0
                        • P Offline
                          P Offline
                          poppw
                          wrote on 6 Sept 2012, 11:38 last edited by
                          #12

                          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]

                          1 Reply Last reply
                          0
                          • R Offline
                            R Offline
                            Rahul Das
                            wrote on 6 Sept 2012, 12:07 last edited by
                            #13

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


                            Declaration of (Platform) independence.

                            1 Reply Last reply
                            0

                            8/13

                            6 Sept 2012, 05:44

                            • Login

                            • Login or register to search.
                            8 out of 13
                            • First post
                              8/13
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved