title: PyQt5 setLayout function causing program to crash?
body: <p>I am using Mark Summerfield's Rapid GUI programming book, which was written for PyQt4, and I am using PyQt5. Some things must be different.</p>
  
  <p>Can anybody see why this is failing on my Linux machine that runs Ubuntu 13.04? It runs on Mint 15 but sometimes ends with a segmentation fault. I think it has to do with the difference between PyQt4 and PyQt5, and I have been looking into the C++ implementation at the qt-project.org website. So far I can tell that QVBoxLayout does inherit from QDialog, and it does have a setLayout function. However, commenting out the last line in the <strong>_<em>init</em>_</strong> function will allow the program to run without crashing, but also without any widgets added to the QDialog box.</p>
  
  <pre><code>import sys
  import PyQt5.QtCore
  import PyQt5.QtGui
  import PyQt5.QtWidgets
  
  class Form(PyQt5.QtWidgets.QDialog):
      def __init__(self, parent=None):
          super(Form, self).__init__(parent)
          self.browser = PyQt5.QtWidgets.QTextBrowser()
          self.lineEdit = PyQt5.QtWidgets.QLineEdit("default statement here")
          self.lineEdit.selectAll()
          layout = PyQt5.QtWidgets.QVBoxLayout()
          layout.addWidget(self.browser)
          layout.addWidget(self.lineEdit)
          self.setLayout(layout)    # &lt;--- program seems to crash here
  
  
  
  app = PyQt5.QtWidgets.QApplication(sys.argv)
  form = Form()
  form.show()
  app.exec_()
  </code></pre>
  
  <p>I get an initial error message like this, repeated about 10 times:</p>
  
  <pre><code>(python3:9896): Gtk-CRITICAL **: IA__gtk_widget_style_get: assertion `GTK_IS_WIDGET (widget)' failed
  </code></pre>
  
  <p>Then it is followed by the following block, which repeats until I kill the program:</p>
  
  <pre><code>QXcbShmImage: shmget() failed (22) for size -524284 (65535x65535)
  QWidget::paintEngine: Should no longer be called
  QPainter::begin: Paint device returned engine == 0, type: 1
  QWidget::paintEngine: Should no longer be called
  QPainter::begin: Paint device returned engine == 0, type: 1
  QPainter::translate: Painter not active
  QPainter::save: Painter not active
  QPainter::setClipRect: Painter not active
  QPainter::pen: Painter not active
  QPainter::setPen: Painter not active
  QPainter::pen: Painter not active
  QPainter::setPen: Painter not active
  QPainter::restore: Unbalanced save/restore
  QWidget::paintEngine: Should no longer be called
  QPainter::begin: Paint device returned engine == 0, type: 1
  QPainter::setClipRect: Painter not active
  [etc, etc, etc...]
  </code></pre>