Is this PyQt 4 python bug or wrongly behaving code?

后端 未结 2 1579
花落未央
花落未央 2021-01-02 03:40

Following code should create the QGraphicsView widget which owns one QGraphicsScene having text inside of it:

#!/usr/bin/python

import sys
from PyQt4.QtGui          


        
2条回答
  •  星月不相逢
    2021-01-02 04:33

    It looks to be related to the QApplication object being deleted when quitting, but I'm not sure why. Your code worked fine for me under Windows but I got the same seg fault output as you under an Ubuntu install.

    I managed to get a clean exit with the following code as a work around.

    #!/usr/bin/python
    
    import sys
    from PyQt4.QtGui import QApplication, QGraphicsView, QGraphicsScene
    
    
    if __name__ == '__main__':
      app = QApplication(sys.argv)
    
      view = QGraphicsView()  
      scene = QGraphicsScene()
    
      scene.addText("Hello!")
    
      view.setScene(scene)
      view.show()
    
      app.exec_()
      app.deleteLater()
      sys.exit()
    

提交回复
热议问题