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. [SOLVED]How to parse html in qt
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]How to parse html in qt

Scheduled Pinned Locked Moved General and Desktop
14 Posts 2 Posters 15.7k Views 1 Watching
  • 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.
  • T Offline
    T Offline
    ThElitEyeS
    wrote on last edited by
    #3

    i have added webkitwidgets in pro file.
    #include <QWebElement>
    #include <QWebFrame>
    in mainwindow.cpp file
    if i try the following
    @
    QWebFrame *frame;
    frame->setHtml("<html></html>");
    QWebElement parse = frame->documentElement();
    @

    its will crash:The program has unexpectedly finished.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #4

      and what happens when you use QWebPage instead of QWebFrame (as is said)?

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • T Offline
        T Offline
        ThElitEyeS
        wrote on last edited by
        #5

        Same thing
        [quote author="raven-worx" date="1372856223"]and what happens when you use QWebPage instead of QWebFrame (as is said)?[/quote]

        @#include <QWebPage>
        QString source(reply->readAll());
        QWebPage *page;
        page->mainFrame()->setHtml(source);@

        The program has unexpectedly finished.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #6

          -can you run your application in your IDE and in debug mode and post the stack trace of the crash.-

          nvm...do this please:
          @
          QWebPage *page = new QWebPage;
          page->mainFrame()->setHtml(source);
          @
          or this
          @
          QWebPage page;
          page.mainFrame()->setHtml(source);
          @

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • T Offline
            T Offline
            ThElitEyeS
            wrote on last edited by
            #7

            2nd one works.
            @ QString source(reply->readAll());
            QWebPage page;
            page.mainFrame()->setHtml(source);
            QWebElement parse = page.mainFrame()->documentElement();
            QWebElement result = parse.findFirst("div[class=result-box]");
            ui->plainTextEdit->setPlainText(result.toPlainText());@
            the last line cause crash
            !http://s16.postimg.org/6dgypgt9h/Screenshot_from_2013_07_03_16_40_27.png(1)!
            !http://s22.postimg.org/j4qwk68wx/Screenshot_from_2013_07_03_16_41_36.png(2)!

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #8

              when working with QWebElement it's good practice to check if the element is null: QWebElement::isNull() ... please check that.
              This happens when the search was unsuccessful for example.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • T Offline
                T Offline
                ThElitEyeS
                wrote on last edited by
                #9

                @QMessageBox::information(this, "T", QString::number(result.isNull()));@
                this breaks the code too

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #10

                  i just tried your code and it is working for me.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    ThElitEyeS
                    wrote on last edited by
                    #11

                    i tried to put <html></html> and its worked, i think the html source i got who make the crash?

                    1 Reply Last reply
                    0
                    • raven-worxR Offline
                      raven-worxR Offline
                      raven-worx
                      Moderators
                      wrote on last edited by
                      #12

                      seems so...maybe this is a bug in the Qt implementation.
                      maybe you can find out what exactly causes the crash? You got the full source code from the network reply. You can save the string and use it for testing which part exactly causes the crash.

                      Did you also try loading another url? Does it only occur on a specific webpage?

                      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                      If you have a question please use the forum so others can benefit from the solution in the future

                      1 Reply Last reply
                      0
                      • T Offline
                        T Offline
                        ThElitEyeS
                        wrote on last edited by
                        #13

                        i have downloaded the latest release qt 5.1.0 and the crash stopped.

                        1 Reply Last reply
                        0
                        • T Offline
                          T Offline
                          ThElitEyeS
                          wrote on last edited by
                          #14

                          thanks for your helping.

                          1 Reply Last reply
                          0

                          • Login

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