title: How to properly set parent of a widget in Pyqt?
body: <p>I have the following code</p>
  
  <pre><code>from PyQt5 import QtCore, QtGui, QtWidgets
  from mw import Ui_MainWindow as mwin
  from wd import Ui_Form as wdg
  
  class widget(QtWidgets.QWidget):
      def __init__(self,parent = None):
              super(widget,self).__init__(parent)
              self.ui = wdg()
              self.ui.setupUi(self)
              self.show()
  
  class Main(QtWidgets.QMainWindow):
      def __init__(self,parent = None):
          super(Main,self).__init__(parent)
          self.ui = mwin()
          self.ui.setupUi(self)
          self.show()
          w = widget(self)
  import sys
  if __name__ == '__main__':
          app = QtWidgets.QApplication(sys.argv)
          mn = Main()
          sys.exit(app.exec_())
  </code></pre>
  
  <p>The Ui is generated by qt designer and is imported from another file.</p>
  
  <p>When I run the code, both the Main window and widget are merged together and a segmentation fault occurs when I close the Main window.</p>
  
  <p>When I set the parent in the widget as None the problem goes but the widget has no parent.</p>
  
  <p>I am unable to understand what is wrong and how to correctly set the Main window as the parent of the widget ?</p>