title: PyQt crashes and thread safety
body: <p>Hello StackExchange community,</p>
  <p>first off, you have all been a great help for me, thanks so much. First time question:</p>
  <p>I am currently writing a PyQt GUI application and I see that it crashes on windows systems, also it gives me a segfault on my machine at home while it works on the one at work (both linux mint 17). After some research, I realize that I have probably created a thread-unsafe GUI because I have several objects that call each others methods.</p>
  <blockquote>
  <p><a href="https://stackoverflow.com/a/8203812/4749250">From another stackoverflow question</a>: <em>GUI widgets may be accessed only from main thread, meaning the thread that calls QApplication.exec(). Access to GUI widgets from any other thread – what you're doing with your calls to self.parent() – is undefined behaviour, in your case this means crashes.</em></p>
  <p><a href="http://doc.qt.io/qt-4.8/threads-qobject.html" rel="nofollow noreferrer">From Qt docs</a>: <em>Although QObject is reentrant, the GUI classes, notably QWidget and all its subclasses, are not reentrant. They can only be used from the main thread. As noted earlier, QCoreApplication::exec() must also be called from that thread.</em></p>
  </blockquote>
  <p>So in the end, I figure that I should only use the signal-slot system for doing so.</p>
  <ol>
  <li>Is this correct?</li>
  <li>Is this only needed for function calls, or can I manipulate the fields of some objects from other objects at runtime in a thread safe manner? for example, I have a options object that is accessed from multiple other objects, and I frequently change parameters there from different sources. Thread safe or unsafe?</li>
  </ol>
  <p>The next thing, is that I have a problem recreating this thread-unsafe behaviour in example code. Qt documentation says that QObjects live in different threads. This means, the following Qt application should be thread unsafe (if I got it correctly).</p>
  <pre><code>from PyQt4 import QtGui
  import sys
  
  class TestWidget(QtGui.QWidget):
      def __init__(self,string):
          super(TestWidget,self).__init__()
          self.button = QtGui.QPushButton(string,parent=self)
          self.button.clicked.connect(self.buttonClicked)
          
          # just to check, and yes, lives in it's own thread
          print self.thread()
          
      def buttonClicked(self):
          # the seemingly problematic line
          self.parent().parent().statusBar().showMessage(self.button.text())
          pass
      pass
  
  class MainWindow(QtGui.QMainWindow):
      def __init__(self):
          super(MainWindow,self).__init__()
          
          Layout = QtGui.QHBoxLayout()
          for string in ['foo','bar']:
              Layout.addWidget(TestWidget(string))
          
          CentralWidget = QtGui.QWidget(self)
          CentralWidget.setLayout(Layout)
          self.setCentralWidget(CentralWidget)
          self.statusBar()
          self.show()
          pass
      pass
  
  if __name__ == '__main__':
      app = QtGui.QApplication(sys.argv)
      M = MainWindow()
      sys.exit(app.exec_())
  </code></pre>
  <p>but it runs on my mine as well on windows machines fine.</p>
  <ol start="3">
  <li>Why? Is this actually thread-unsafe and could crash, but it just doesn't?</li>
  </ol>
  <p>Thanks for helping me to sort this out ...</p>