0

I'm modifying the DOM Traversal example that comes with Qt. However, whenever I see a link, I want to "go" to that URL and also traverse its DOM, but I don't want to reload the GUI. Right now I'm still using the code from the example to get the homepage:

void Window::on_webView_loadFinished()
{
    treeWidget->clear();

    QWebFrame *frame = webView->page()->mainFrame();
    QWebElement document = frame->documentElement();

    examineChildElements(document, treeWidget->invisibleRootItem());
}

This works great. In examineChildElements(), when I encounter a specific link, I then call another function with the URL (I checked the URL string; it's correct):

void Window::parse_page(QString page_URL)
{
    QWebView *innerPage = new QWebView();
    innerPage->setUrl(page_URL);
    QWebFrame *frameInner = innerPage->page()->mainFrame();
    QWebElement documentBetrieb = frameInner->documentElement();

    get_biz_info(documentBetrieb);
    delete innerPage;
    return;
}

But when I traverse this document (documentBetrieb), there is only an HTML tag. Is there a step I'm missing, or a way of putting the DOM from a URL directly into a QWebElement without using QWebView?

MrUser
  • 1,187
  • 15
  • 25

1 Answers1

0

Are you sure setUrl() is loading the URL synchronously? I suppose you need listen to QWebView::loadFinished(bool ok) signal before accessing the DOM.

Silicomancer
  • 8,604
  • 10
  • 63
  • 130
  • How do I listen to a signal from a dynamic object? Can I use connect() for this purpose? – MrUser Jun 26 '14 at 13:28
  • Yes, use connect(). Of course if you try this you should not delete the web view before you received the signal finished your operations. – Silicomancer Jun 26 '14 at 13:41
  • I use connect() to connect a local slot, then call QWebView->load() and sit in a while() loop. However, the slot is never called, so I get stuck in the while() loop. – MrUser Jun 26 '14 at 13:45
  • Of course you need an active event loop for such an application to run. Have you ever build a Qt application before? – Silicomancer Jun 26 '14 at 13:52
  • Just once, but it didn't have dynamic signals/slots like this. I have app.exec() in main(), is the active event loop to which you are referring? – MrUser Jun 26 '14 at 14:02
  • Yes, exec() runs the event loop. Your application should be driven by that loop. I propose you should read about Qt fundamentals and architecture first to make your work easier. – Silicomancer Jun 26 '14 at 14:17