Reputation: 23
Trying to open 2 windows using PyQt5 we experienced a brutal python exit with segmentation error message.
The minimal reproducing error is:
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5 import QtCore, QtGui, QtWidgets
>>> def application():
... import sys
... app = QtWidgets.QApplication(sys.argv)
... Dialog = QtWidgets.QDialog()
... Dialog.show()
... app.exec_()
...
>>> import sys
>>> app = QtWidgets.QApplication(sys.argv)
>>> MainWindow = QtWidgets.QMainWindow()
>>> list = application()
>>> MainWindow.show()
Segmentation error (core dumped)
We suspect that the first window hamper the second window opening. How can we open the two windows without problem ?
Upvotes: 0
Views: 382
Reputation: 23
You're right, it's because I've created 2 QApplication objects that I have a problem. Also this program works with this code:
from PyQt5 import QtCore, QtGui, QtWidgets
def application():
import sys
Dialog = QtWidgets.QDialog()
Dialog.show()
app.exec_()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
list = application()
MainWindow.show()
sys.exit(app.exec_())
Upvotes: 1