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 );
    view->load(QUrl("http://cplus.kompf.de/artikel/container.html"));
    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);
    /
    //QWebFrame
    frame = page->mainFrame();
    QWebFrame
    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 = doc.at( 1 ).firstChild();
    // QWebElement bla2 = bla1.nextSibling();
    // int c1 = doc.at(1).findAll("input").count();
    QString t1 = all.at(1).tagName();
    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 "http://cplus.kompf.de/artikel/container.html" should be inside webframe, but console output always gives me
    BODY
    <html><head></head><body><p>First Paragraph
    tml><html><head></head><body></body></html>

    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.

    Cheers



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