10

我怀疑这是非常基本的,没有人愿意记录它。

我想从我的程序中编写一个 HTML 文件,然后将该文件加载到 QWebview 对象中。

当我打开 QtCreator 时,我可以导航到右侧 URL 块中的文件,它会显示在 QtCreator 中。当我编译并运行程序时,窗口是白色和空白的。

我也不希望目录硬编码,我希望它使用当前目录。

所以我想有两个问题:

  1. 怎么写???在下面获取名为“reportView”的QWebview对象来显示我的本地文件?

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

  1. 为什么 QWebview 对象保持空白?我怀疑连接到 Google Docs 时出现问题,因为我收到此错误:

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

谢谢你。

4

2 回答 2

21

来自网络

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

从资源

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

从文件系统

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

不需要QUrl::FromLocalFile,不需要webView->show()

不客气!

于 2014-01-26T16:43:40.537 回答
9

您可以使用QUrl::fromLocalFile它将"file:///path/to/file.html"从绝对文件路径构造这样的 URL。

Google 使用 SSL,如果您在 Windows 上,则需要手动安装OpenSSL并将其 DLL 复制到 Windows 系统目录、Qt 安装的 bin 目录或最终的可执行文件夹中。

其他平台应该已经安装了 OpenSSL 或包管理器来安装它。

于 2012-03-15T02:01:16.260 回答