Nominate our 2022 Qt Champions!

Creating a frame from HTML and parsing it

  • Hello
    I'd would like to parse some HTML in -QT- Qt. I've found a lot of tutorials, but I have a hard time understanding one detail:

    @ frame->setHtml(HTML);
    QWebElement document = frame->documentElement();
    QList<QWebElement> imgs = document.findAll("table");

    What does "frame" refer to? I guess it's to a "QWebFrame" object, but how should I handle this? I have some HTML stored as a
    QString, and would like to parse this, but:

    @QWebFrame *frame = new QWebFrame();@

    does not work... How can I create a frame and set the HTML to it? Thanks!

  • I think you can't, you have to create a page and access its frame like this:

    @QWebPage page ();
    page.mainFrame()->setHtml(htmlString, QUrl::fromLocalFile("C:\someFolder");

    In case you want to display the html I'd recommend you use a QWebView
    @QWebView* webView = new QWebView (parent);
    webView->setHtml(htmlString, QUrl::fromLocalFile("C:\someFolder");
    QWebElementCollection image = webView->page()->mainFrame()->findAllElements("img");
    if(image.count() > 0)
    {"src", filePathString);

Log in to reply