pyQt5 将文件对象传递给 QWebEngineView
pyQt5 pass a file object to QWebEngineView
如何将主应用程序中打开的文件发送到QWebEngineView中的页面并通过javascript FileReader((函数处理它,因为它是由QWebEngineView中的html5文件输入打开
的这是我代码的一部分
# -*- coding: utf-8 -*-
import sys, os
from PyQt5.QtWidgets import ( QApplication, QMainWindow)
from PyQt5.QtCore import QUrl
import PyQt5.QtWebEngineWidgets as QtWebEngineWidgets
import interface
class MyWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.ui = interface.Ui_MainWindow()
self.ui.setupUi(self)
web_view = QtWebEngineWidgets.QWebEngineView()
self.web_view = web_view
self.ui.verticalLayout_navigateur.addWidget(web_view)
url = self.local_url("src/index.html")
self.web_view.load(url)
f = open('myfile.json', 'r')
#send f to self.web_view and handle it by javascript FileReader() function
def local_url(self, relativePath):
absolutePath = os.path.abspath(relativePath)
url = QUrl.fromLocalFile(absolutePath)
return url
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
谢谢
我找到了另一种解决方案,它非常简单,而不是发送对象文件来读取 JavaScript,我只需要在主应用程序中读取它并通过 QWebChannel 注入内容
相关文章:
- 如何从Qt QWebEngineView获取HTTP状态代码
- 如何使用QWebEngineView忽略SSL证书错误
- Qt QWebEngineView 不允许加载本地资源
- 如何从 qwebengineview qt5.9 中提取数据
- qwebengineview 组件在我的系统中不存在
- 使用 Lamda 从 QWebEngineView 中的 QWebEnginePage 获取 HTML
- 如何包含QwebEngineView而不会出错
- 如何将QWebEngineView渲染到打印机?
- pyQt5 将文件对象传递给 QWebEngineView
- QWebEngineView仅在javascript脚本完成后显示页面
- 如何在QWebEngineView中将值从QML传递到JavaScript
- QWEBENGINEVIEW-从资源加载HTML
- QWebEngineView立即崩溃,尤其是在滚动后 - Qt5.8
- QWebEngineView & API Access Token fetching
- 如何让QWebEngineView全屏显示?
- QT QWEBVIEW,QWEBENGINEVIEW不起作用
- QWEBENGINEVIEW请求身体拦截
- 如果 QApplication 执行延迟,QWebEngineView 在加载内容时会以静默方式失败
- Qt 如何获取发送者信号的发送者或如何知道 QWebEngineView 的加载启动网址
- 如何在QWebEngineView中模拟linkClicked(QUrl)信号