0

我正在尝试加载静态 html 页面,但加载页面为假。(这在本地工作,但不在 docker 容器内)。

该文件loadProgress为 100%,但我得到 OK 信号,false表明加载页面时出错。我正在尝试使用 ErrorPageExtension (从网上找到)来找出详细的错误消息是什么。在加载页面时出现错误时,有人可以说明如何调用扩展程序吗?我错过了什么吗?

  def setupWebView(self):
    # setting up web view objects
    #bla bla
    self._extension_handlers = {
      QWebPage.ErrorPageExtension: self._handle_errorpage,
    }

  def loadSetPage(self):
    print(":: OS Path is:"+os.getcwd())
    self.url2 = QUrl("file://"+os.getcwd()+"/dist/index.html")
    self.web2.load(self.url2)
    print("Checking if Load Page was successful")
    self.web2.loadFinished.connect(self.testIfPageLoaded)


  def testIfPageLoaded(self, ok):
    print(":: Loading of page finished successfully")
    testhtml = self.web2.page().currentFrame().toHtml()
    print(ok)  ##

 def _handle_errorpage(self, info, errorPage):
    # catch the error, populate self.errorInfo and return an error page
    info = sip.cast(info, QWebPage.ErrorPageExtensionOption)
    print("The error loading page is : "+info.errorString)
    return True

  def supportsExtension(self, ext):
    return ext in self._extension_handlers

  def extension(self, ext, opt, out):
    try:
      handler = self._extension_handlers[ext]
    except KeyError:
      print("Extension {} not supported!".format(ext))
      return super().extension(ext, opt, out)
    return handler(opt, out)
4

0 回答 0