JChan
JChan

Reputation: 1451

How to display a web page using QT/C++

I am trying to display a web page using the below code

    QWebView *view = new QWebView();
    view->load(QUrl("qrc://images//sample page.html/"));
    view->show();

sample page.html is added to project resources/Images. The web page frame is loading, but I can't see any html data.

I tested with the below web url and it loaded the page

   view->load(QUrl("http://www.google.com/"));

Upvotes: 4

Views: 4527

Answers (1)

dirkgently
dirkgently

Reputation: 111130

You will have to go through a few steps as follows:

1) Get the QWebPage object:

 QWebPage *page = view->page();

2) Get the QWebFrame object:

 QWebFrame *frame = page->currentFrame();

3) Call the toHtml member function on the current frame:

 QString html = frame->toHtml();

Of course, you will need to add appropriate error checks in between.

Upvotes: 3

Related Questions