I run into a strange behavior, where my QApplication seems not initialize correctly.
I have two modules: foo.py
and bar.py
.
bar.py
content:
module: bar
from PyQt4 import QtGui
class MyTreeView(QtGui.QTreeView):
def __init__(self, name, parent=None):
super(MyTreeView, self).__init__(parent)
foo.py
content:
# module: foo
from PyQt4 import QtGui
import bar
class MyDialog(QtGui.QDialog):
def __init__(self, name, parent=None):
super(MyDialog, self).__init__(parent)
self._name = name
self.setMinimumSize(500, 200)
self.setLayout(QtGui.QHBoxLayout())
self._tree = bar.MyTreeView(name)
self.layout().addWidget(self._tree)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
dialog = MyDialog('foo')
dialog.exec_()
sys.exit(app.exec_())
When running foo.py
I get the following error message:
QWidget: Must construct a QApplication before a QPaintDevice
The debugger stops while calling the QTreeView constructor:
super(MyTreeView, self).__init__(parent)
What's going wrong here?
System: Windows 7
Python: 2.7.9
PyQt: PyQt4
- 4.8.6