简体   繁体   中英

Python has stopped working in PyQt application

code like the following .After it running for about half a minute ,then close the window, then the "Python has stopped working" dialog pops up(you had better try more than once. ) I wonder why this happen ?any solution to this ? ​ Tested on Windows with PyQt4-4.11.3-gpl-Py3.4-Qt4.8.6-x32.exe

from PyQt4.QtCore import *
from PyQt4.QtGui import *


class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()

        self.setWindowIcon(QIcon("./wa.png"))
        self.createTrayIcon()

    def createTrayIcon(self):

        self.trayIcon = QSystemTrayIcon()
        self.trayIcon.setIcon(self.windowIcon())
        self.trayIcon.show()


if __name__ == "__main__":
    import sys
    app = QApplication(sys.argv)

    ui = MainWindow()
    ui.show()
    sys.exit(app.exec_())

I do my PyQt work on linux, so there might be differences, but usually I construct my MainWindow with the following call:

class MainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        ...

I can run your code in python3, but after I exit I get the Segmentation Fault. If I change the constructor to what I indicated above the Fault is not reproduced.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM