keelerjr12
keelerjr12

Reputation: 1933

QWebView not displaying simple HTML

My Qt code is pretty simple:

#include <QtGui>
#include <QWebView>

int main(int argc, char** argv) {

  QApplication app(argc, argv);

  QWebView* view = new QWebView;
  view->setUrl(QUrl::fromLocalFile("C:\\Users\\Me\\Documents\\website.html"));
  view->show();

  return app.exec();
}

However, this just displays a blank page when the application starts up. Any ideas? I'm trying to follow simple tutorials and have searched. I even tried loading Google and that failed.

Upvotes: 1

Views: 2866

Answers (2)

chacham15
chacham15

Reputation: 14281

You need to add the following setting:

view.settings()->setAttribute(QWebSettings::LocalContentCanAccessFileUrls,true);

Upvotes: 2

keelerjr12
keelerjr12

Reputation: 1933

I found the solution, I had to set the proxy settings. My code looks like this:

#include <QApplication>
#include <QNetworkProxy>
#include <QWebView>
#include <QUrl>

int main(int argc, char** argv) {

  QApplication app(argc, argv);

  QNetworkProxy proxy;
  proxy.setType(QNetworkProxy::HttpProxy);
  proxy.setHostName(QString("PROXY_IP_ADDRESS"));
  proxy.setPort(PROXY_PORT);
  QNetworkProxy::setApplicationProxy(proxy);

  QWebView view;
  view.load(QUrl("http://www.google.com"));
  view.showFullScreen();

  return app.exec();
}

Upvotes: 2

Related Questions