Python : about pyqt5 QtWebEngineWidgets How to kill Qt Qtwebengineprocess process

0

In main-windows I have built a browser to show the web and four button ,when click the second button a new browser will show ,at the same time the process:"Qt Qtwebengineprocess"will show in Task Manager.when I closed the new browser this process will not be killed, and then open again ,one more "Qt Qtwebengineprocess"will be there ,the old one still existence.several times again the program will Stucked ,show the error codeļ¼šProcess finished with exit code -1073741819 (0xC0000005).

the first pythonfile:mainpy.py

import sys
import webbrowser
from PyQt5.QtCore import pyqtSlot, QEventLoop, QObject, QPointF, QUrl
from PyQt5.QtWidgets import QApplication, QDialog, QPushButton, QVBoxLayout, QWidget
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
from PyQt5 import QtCore, QtGui, QtWidgets
import study1

weburl = ''
class Widget(QWidget):
    #app = QApplication.instance()
    def __init__(self, parent=None):
        super().__init__(parent)
        self.setGeometry(400, 400, 1250, 865)
        self.setFixedSize(self.width(), self.height())
        self.view = QWebEngineView(self)
        self.view.load(QUrl("http://www.baidu.com"))
        self.view.setGeometry(QtCore.QRect(10, 10, 1230, 675))
        self.button1 = QPushButton(self)
        self.button1.setText("button1")
        self.button1.setGeometry(QtCore.QRect(10, 705, 300, 150))
        self.button2 = QPushButton(self)
        self.button2.setText("button2")
        self.button2.setGeometry(QtCore.QRect(320, 705, 300, 150))
        self.button3 = QPushButton(self)
        self.button3.setText("button3")
        self.button3.setGeometry(QtCore.QRect(630, 705, 300, 150))
        self.button4 = QPushButton(self)
        self.button4.setText("button4")
        self.button4.setGeometry(QtCore.QRect(940, 705, 300, 150))
        self.button1.clicked.connect(self.veltest)
        self.button2.clicked.connect(self.vecc)
        self.setFocus()
    def veltest(self):
        webbrowser.open('http://www.baidu.com')
    def vecc(self):
        study1.startnewwindow()

app = QApplication(sys.argv)
if __name__ == "__main__":
    app = QApplication.instance()
    w = Widget()
    w.show()
    sys.exit(app.exec_())

the second pythonfile study1.py

from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import pyqtSlot, QEventLoop, QObject, QPointF, QUrl
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
#import analyse
import mainpy
windowList1 = []
def startnewwindow():
    app = QApplication.instance()

    window = MainWindow()

    window.show()
    windowList1.append(window)

    app.exec_()

class MainWindow(QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.setWindowTitle('My Browser')
        self.setWindowIcon(QIcon('icons/penguin.png'))         
        self.resize(1500, 900)
        self.show()
        # set browser
        self.browser = WebEngineView()
        #url = 'http://ids.vecc-mep.org.cn/Ids/op/index.jsp'
        url = 'http://www.hao123.com'
        self.browser.setUrl(QUrl(url))
        self.setCentralWidget(self.browser)

        navigation_bar = QToolBar('Navigation')
        navigation_bar.setIconSize(QSize(32, 32))
        self.addToolBar(navigation_bar)

        back_button = QAction(QIcon('icon/back.png'), 'Back', self)
        next_button = QAction(QIcon('icon/next.png'), 'Forward', self)
        stop_button = QAction(QIcon('icon/stop.png'), 'stop', self)
        reload_button = QAction(QIcon('icon/refresh.png'), 'reload', self)
        download_button = QAction(QIcon('icon/fenxi.png'), 'download', self)
        back_button.triggered.connect(self.browser.back)
        next_button.triggered.connect(self.browser.forward)
        stop_button.triggered.connect(self.browser.stop)
        reload_button.triggered.connect(self.browser.reload)
        download_button.triggered.connect(self.download)

        navigation_bar.addAction(back_button)
        navigation_bar.addAction(next_button)
        navigation_bar.addAction(stop_button)
        navigation_bar.addAction(reload_button)
        navigation_bar.addAction(download_button)

        self.urlbar = QLineEdit()
        self.urlbar.returnPressed.connect(self.navigate_to_url)
        navigation_bar.addSeparator()
        navigation_bar.addWidget(self.urlbar)

        self.browser.urlChanged.connect(self.renew_urlbar)
    def navigate_to_url(self):
        q = QUrl(self.urlbar.text())
        if q.scheme() == '':
            q.setScheme('http')
        self.browser.setUrl(q)
    def renew_urlbar(self, q):

         self.urlbar.setText(q.toString())
         self.urlbar.setCursorPosition(0)
    #def download(self):

        #q = QUrl(self.urlbar.text())
        #mainpy.weburl = q.toString()
        #analyse.startread()

#for creat new windows
class WebEngineView(QWebEngineView):
    app = QApplication.instance()
    def createWindow(self, QWebEnginePage_WebWindowType):
        #app = QApplication.instance()
        new_window = MainWindow()
        new_window.show()
        windowList1.append(new_window)  
        return new_window.browser

enter image description here

python
python-3.x
pyqt
pyqt5
qwebengineview
asked on Stack Overflow Mar 26, 2020 by jianfeng ding • edited Mar 26, 2020 by jianfeng ding

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0