<legend id='L9Ypm'><style id='L9Ypm'><dir id='L9Ypm'><q id='L9Ypm'></q></dir></style></legend>
  • <tfoot id='L9Ypm'></tfoot>

      <small id='L9Ypm'></small><noframes id='L9Ypm'>

        <bdo id='L9Ypm'></bdo><ul id='L9Ypm'></ul>

      1. <i id='L9Ypm'><tr id='L9Ypm'><dt id='L9Ypm'><q id='L9Ypm'><span id='L9Ypm'><b id='L9Ypm'><form id='L9Ypm'><ins id='L9Ypm'></ins><ul id='L9Ypm'></ul><sub id='L9Ypm'></sub></form><legend id='L9Ypm'></legend><bdo id='L9Ypm'><pre id='L9Ypm'><center id='L9Ypm'></center></pre></bdo></b><th id='L9Ypm'></th></span></q></dt></tr></i><div id='L9Ypm'><tfoot id='L9Ypm'></tfoot><dl id='L9Ypm'><fieldset id='L9Ypm'></fieldset></dl></div>
      2. QWebEngineView - 加载&gt;2mb 内容

        时间:2023-08-07

          <tfoot id='TTIbC'></tfoot>
          <i id='TTIbC'><tr id='TTIbC'><dt id='TTIbC'><q id='TTIbC'><span id='TTIbC'><b id='TTIbC'><form id='TTIbC'><ins id='TTIbC'></ins><ul id='TTIbC'></ul><sub id='TTIbC'></sub></form><legend id='TTIbC'></legend><bdo id='TTIbC'><pre id='TTIbC'><center id='TTIbC'></center></pre></bdo></b><th id='TTIbC'></th></span></q></dt></tr></i><div id='TTIbC'><tfoot id='TTIbC'></tfoot><dl id='TTIbC'><fieldset id='TTIbC'></fieldset></dl></div>
            <bdo id='TTIbC'></bdo><ul id='TTIbC'></ul>

                • <small id='TTIbC'></small><noframes id='TTIbC'>

                  <legend id='TTIbC'><style id='TTIbC'><dir id='TTIbC'><q id='TTIbC'></q></dir></style></legend>
                    <tbody id='TTIbC'></tbody>
                  本文介绍了QWebEngineView - 加载&gt;2mb 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  因此,使用 PyQt5 的 QWebEngineView 以及 .setHTML 和 .setContent 方法有 2 MB 的大小限制.在谷歌上寻找解决方案时,我发现了两种方法:

                  So, using PyQt5's QWebEngineView and the .setHTML and .setContent methods have a 2 MB size limitation. When googling for solutions around this, I found two methods:

                  使用 SimpleHTTPServer 提供文件.然而,这被公司使用的防火墙破坏了.

                  Use SimpleHTTPServer to serve the file. This however gets nuked by a firewall employed in the company.

                  使用文件 URL 并指向本地文件.然而,这是一个相当糟糕的解决方案,因为 HTML 包含机密数据,在任何情况下我都不能将其留在硬盘上.

                  Use File Urls and point to local files. This however is a rather bad solution, as the HTML contains confidential data and I can't leave it on the harddrive, under any circumstance.

                  我目前看到的最佳解决方案是使用文件 url,并在程序退出/当 loadCompleted 报告完成时删除文件,以先到者为准.

                  The best solution I currently see is to use file urls, and get rid of the file on program exit/when loadCompleted reports it is done, whichever comes first.

                  但这不是一个很好的解决方案,我想问一下是否有一个我忽略的解决方案会更好?

                  This is however not a great solution and I wanted to ask if there is a solution I'm overlooking that would be better?

                  推荐答案

                  为什么不通过自定义 url 方案处理程序加载/链接大部分内容?

                  Why don't you load/link most of the content through a custom url scheme handler?

                  webEngineView->page()->profile()->installUrlSchemeHandler("app", new UrlSchemeHandler(e));
                  
                  class UrlSchemeHandler : public QWebEngineUrlSchemeHandler
                  {   Q_OBJECT
                  public:
                      void requestStarted(QWebEngineUrlRequestJob *request) {
                          QUrl url = request->requestUrl();
                          QString filePath = url.path().mid(1);
                          // get the data for this url
                          QByteArray data = ..
                          // 
                          if (!data.isEmpty()) 
                          {
                              QMimeDatabase db;
                              QString contentType = db.mimeTypeForFileNameAndData(filePath,data).name();
                              QBuffer *buffer = new QBuffer();
                              buffer->open(QIODevice::WriteOnly);
                              buffer->write(data);
                              buffer->close();
                              connect(request, SIGNAL(destroyed()), buffer, SLOT(deleteLater()));
                              request->reply(contentType.toUtf8(), buffer);
                          } else {
                              request->fail(QWebEngineUrlRequestJob::UrlNotFound);
                          }
                      }
                  };
                  

                  然后您可以通过 webEngineView->load(new QUrl("app://start.html"));

                  内部的所有相对路径也将转发到您的 UrlSchemeHandler..

                  All relative pathes from inside will also be forwarded to your UrlSchemeHandler..

                  记得添加相应的包含

                  #include <QWebEngineUrlRequestJob>
                  #include <QWebEngineUrlSchemeHandler>
                  #include <QBuffer>
                  

                  这篇关于QWebEngineView - 加载&gt;2mb 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在 PyQt5 中自定义 QGroupBox 标题? 下一篇:我如何在 pyqt5 中使用 QTextEdit 来显示 html 的所有

                  相关文章

                  最新文章

                • <tfoot id='VjNEb'></tfoot>
                  • <bdo id='VjNEb'></bdo><ul id='VjNEb'></ul>
                • <legend id='VjNEb'><style id='VjNEb'><dir id='VjNEb'><q id='VjNEb'></q></dir></style></legend>

                      <i id='VjNEb'><tr id='VjNEb'><dt id='VjNEb'><q id='VjNEb'><span id='VjNEb'><b id='VjNEb'><form id='VjNEb'><ins id='VjNEb'></ins><ul id='VjNEb'></ul><sub id='VjNEb'></sub></form><legend id='VjNEb'></legend><bdo id='VjNEb'><pre id='VjNEb'><center id='VjNEb'></center></pre></bdo></b><th id='VjNEb'></th></span></q></dt></tr></i><div id='VjNEb'><tfoot id='VjNEb'></tfoot><dl id='VjNEb'><fieldset id='VjNEb'></fieldset></dl></div>
                    1. <small id='VjNEb'></small><noframes id='VjNEb'>