0

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

MagSec
  • 346
  • 4
  • 17
  • 1
    Works fine for me. Surely you're not really using pyqt-**4.8.6** (released 2011)?! That's probably your qt version. – ekhumoro Feb 26 '18 at 02:06
  • Works fine for me too, running with PySide version 1.2.4 – Yohboy Feb 26 '18 at 08:20
  • I suspect the bar.py shown is not what is actually in the file – three_pineapples Feb 26 '18 at 09:25
  • as three_pineapples allready said, you probably have some more in your `bar.py`. Move the import of bar.py after the constructor of QApplication and do the class declearation, using the bar import, later as well – Skandix Feb 28 '18 at 15:17

0 Answers0