“Must construct a QApplication before a QPaintDevice” from QWidget

前端 未结 2 1553
余生分开走
余生分开走 2020-11-30 11:51

I\'m busy porting an IRC client from Python 2.6 to 3.3 and I\'ve stumbled across a problem with PyQt. The application originally used PyQt4, I\'m also recoding it to get it

2条回答
  •  Happy的楠姐
    2020-11-30 12:33

    I'm afraid single file will not be enough in this situation - the execution flow is not clear just from this one module. The message in question usually appears when you try to use some resources/create some objects that require initialized QApplication - like QIcon, for example.

    Instantiation of Qt-based GUI application usually looks like this:

    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        main_window = MainWindowClass()
        main_window.show()
        sys.exit(app.exec_())
    

提交回复
热议问题