QWebEngineView 加载 [duplicate] 后立即关闭

QWebEngineView closes immediately after loading [duplicate]

提问人:Sourav Mandal 提问时间:10/7/2023 更新时间:10/7/2023 访问量:22

问:

我在使用Mainwindow的QWebEngineView时遇到问题。它在打开后立即关闭。我的问题的图形视图

这个独立的代码运行良好:

url = 'https://google.com'

app = QApplication(sys.argv)

# QWebEngineView
iframe = QWebEngineView()
iframe.load(QUrl(url))
iframe.show()

sys.exit(app.exec_())

但是当我将此功能添加到我的项目中时,问题出现了:

from PySide6.QtWidgets import QMainWindow
from ui_widget import Ui_Widget
from iframe import Iframe

class Widget(QMainWindow, Ui_Widget):
    def __init__(self, app):
        super().__init__()
        self.app = app
        self.setupUi(self)
        self.setWindowTitle('Untitled[*] - Notepad')


        self.actionSend_Feedback.triggered.connect(self.feedback)


    def feedback(self):
        url = 'https://ciomic.com'
        feedback = Iframe(url)
        feedback.show()


from PySide6.QtCore import QUrl
from PySide6.QtWebEngineWidgets import QWebEngineView

class Iframe(QWebEngineView):
    def __init__(self, url):
        super().__init__()
        self.load(QUrl(url))
        self.show()


import sys
from PySide6 import QtWidgets
from widget import Widget
    
app = QtWidgets.QApplication(sys.argv)

window = Widget(app)
window.show()

sys.exit(app.exec())
python pyside6 qmainwindow qwebengineview

评论

0赞 musicamante 10/7/2023
该对象在函数返回后立即被垃圾回收。使其成为实例属性。feedback

答: 暂无答案