How do I display local HTML in QWebview?

后端 未结 2 1004
长情又很酷
长情又很酷 2021-02-08 13:35

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.

Whe

相关标签:
2条回答
  • 2021-02-08 13:50

    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.

    0 讨论(0)
  • 2021-02-08 13:58

    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!

    0 讨论(0)
提交回复
热议问题