Help with QtWebPage/Frame please

  • I have already seached the Forum but couldn't find any hint to where my mistake may be.
    relevant code:
    @view = new QWebView( splitter );
    QWebPage page = view->page();
    /page->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
    page->settings()->setAttribute(QWebSettings::PluginsEnabled, false);
    page->settings()->setAttribute(QWebSettings::AutoLoadImages, false);
    page->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, false);
    frame = page->mainFrame();
    frame = page->currentFrame();
    QString webHtml = frame->toHtml();
    //frame->setHtml( "<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>");
    QWebElement document = frame->documentElement();
    QWebElementCollection all = view->page()->mainFrame()->findAllElements("
    QWebElementCollection findBody = document.findAll("body");
    int c = all.count();
    int d = findBody.count();
    //QWebElement bla1 = 1 ).firstChild();
    // QWebElement bla2 = bla1.nextSibling();
    // int c1 ="input").count();
    QString t1 =;
    QString t0 = frame->toHtml();

    std::cout << t1.toLocal8Bit().data() << std::endl;
    std::cout << t0.toLocal8Bit().data();
    std::cout << webHtml.toLocal8Bit().data();@

    when i set the frame myself with frame->setHtml( "<html><body><p>First Paragraph</p><p>Second Paragraph</p></body></html>"); console output returns me exactly this html code. So in this case, programm is working as expected.
    As soon as I comment it out, the frame of "" should be inside webframe, but console output always gives me
    <html><head></head><body><p>First Paragraph

    no matter which page I try.
    I am sure that isn't really the true frame of the page.
    Sorry for my english , I would be happy if someone could help me with this webpage webframe functionallity.


  • Calling QWebView::load(...) will start downloading the data asynchronously ... so, you will have to wait until loadFinished() is emitted and interact with the DOM in a slot-function

    ... and maybe your project doesn't rebuild cleanly, at least that is the only way I see how you could get the text that you commented out ...

  • Ahh thank you, loadFinished() Signal solved my problem, wonder why I didn't stumble about it somewhere else. Thanks a lot!

Log in to reply

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