10

I suspect this is so basic that no one bothered to document it.

I want to write an HTML file from my program, and then load that file into a QWebview object.

When I have QtCreator open, I can navigate to the file in the URL block on the right and it displays within QtCreator. When I compile and run the program, the window is white and blank.

I also don't want the directory hardcoded, I want it to use the current directory.

So I guess there are two questions:

  1. How do I write the ??? in the following to get the QWebview object named "reportView" to display my local file?

ui->reportView->load(QUrl("???"));

  1. Why does the QWebview object remain blank? I suspect a problem connecting to Google Docs because I get this error:

QSslSocket: cannot call unresolved function SSLv23_client_method
QSslSocket: cannot call unresolved function SSL_CTX_new
QSslSocket: cannot call unresolved function SSL_library_init
QSslSocket: cannot call unresolved function ERR_get_error

Thank you.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
RuQu
  • 243
  • 3
  • 4
  • 9

2 Answers2

21

From the web

webView->load(QUrl("http://google.de"));

From resource

webView->load(QUrl("qrc:///sample.html"));

From File System

webView->load(QUrl("file:///C:/sample.htm"));

No need for QUrl::FromLocalFile, no need for webView->show()

You are all welcome!

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Kris Jobs
  • 698
  • 11
  • 12
9

You can use QUrl::fromLocalFile which will construct an URL like this "file:///path/to/file.html" from an absolute file path.

Google uses SSL, and if you are on Windows you need to manually install OpenSSL and copy its DLLs in Windows system directory, in the bin directory of the Qt installation, or in your final executable folder.

Other platforms should either already have OpenSSL installed or a package manager to install it.

alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • If I build it statically, will it automatically include these DLLs for distribution or do I need to change something in the .pro file to set that? – RuQu Mar 15 '12 at 03:24
  • You have to run Qt's "configure" with the option "-openssl-linked" and recompile Qt (or maybe just the QtNetwork module). – alexisdm Mar 15 '12 at 16:12