0

I tried to make pyqt5 application with QWebEnginePage rebootable. But got segfault. Here is code sample:

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import qApp
#from PyQt5.QtWebEngineWidgets import QWebEnginePage

from PyQt5.QtCore import QTimer

from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWebEngineWidgets import QWebEngineView

class MainWindow(QMainWindow):
    EXIT_CODE_REBOOT = -123
    def __init__(self,parent=None):
        QMainWindow.__init__(self, parent)
        self.timer = QTimer()
        self.timer.timeout.connect(self.restart)
        self.timer.start(3 * 1000)

        self.qwe = QWebEngineView()
        #self.qp = QWebEnginePage()  # uncomment this will cause Segmentation fault (core dumped)

    def restart(self):
        print('restart')
        qApp.exit(MainWindow.EXIT_CODE_REBOOT)


if __name__=="__main__":
    currentExitCode = MainWindow.EXIT_CODE_REBOOT
    while currentExitCode == MainWindow.EXIT_CODE_REBOOT:
        print('next..')
        a = QApplication(sys.argv)
        w = MainWindow()
        w.show()
        currentExitCode = a.exec_()
        a = None

With this comments - it works fine. But if remove comment's 'Segmentation fault (core dumped)' appears.

Can you give me an advice for this?

EDIT

Reproduced on PyQt 5.9.3 and Ubuntu 14.04

Community
  • 1
  • 1
Raj
  • 41
  • 5
  • I tried it in Qt 5.9.3 in Arch Linux and it does not generate that error. – eyllanesc Jan 24 '18 at 14:44
  • @eyllanesc you are talking about version without comments? It has to print 'next' several times. – Raj Jan 24 '18 at 15:27
  • That's why I say it works well, it does not generate Segmentation fault (core dumped), it prints `next` every time the timer fires. – eyllanesc Jan 24 '18 at 15:35
  • I just saw your code better and I see that I have to uncomment a line, I'm going to try again. – eyllanesc Jan 24 '18 at 15:36
  • @Raj. Put the `a = QApplication(sys.argv)` line before the while loop and remove the `a = None` line. It is never safe to create more than one QApplication (even if you try to delete the old one). – ekhumoro Jan 24 '18 at 18:55
  • @ekhumoro I know about that QApplication should be created only once. But behavior in my example is quite strange. I expected that it wouldn't work in both cases. – Raj Jan 26 '18 at 07:39
  • @Raj. If you know that, why did you have that expectation? And why would care about it, anyway? What *practical* use-case do you have for re-creating application objects? What *specific* problem are you trying to solve? – ekhumoro Jan 26 '18 at 17:25

1 Answers1

0

Same error when I used anaconda PyQt5

I installed PyQt5 by

conda install -c anaconda pyqt

error result:

>>> from PyQt5 import *
>>> from PyQt5.QtGui import *
Segmentation fault (core dumped)

solved by:

pip install PyQt5

result:

>>> from PyQt5 import *
>>> from PyQt5.QtGui import *
>>> 

Hope it works!

Harriet.O
  • 419
  • 1
  • 5
  • 8