1

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.

2 Answers 2

2

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

You may also need to use proxy.setUser and proxy.setPassword depending on your system configuration.
2

You need to add the following setting:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.