title: QThread: Threading with GUI python
body: <p>I am making mini chat application to improve my socket and GUI skills in Python. But my QThread is dumping every time when I'm launching application.
  I need to run Thread with GUI
  Here it is <em>client.py</em></p>
  <pre><code>import socket
  import sys
  from colorama import Fore, Back, Style
  from os import system, name
  import sys
  from chat import Ui_Form as Ui_Form
  from login  import Ui_Form as Ui_Form1
  from PyQt5 import QtCore, QtGui, QtWidgets
  from threading import Thread
  
  sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  
  app = QtWidgets.QApplication(sys.argv)
  Form_login = QtWidgets.QWidget()
  ui_login = Ui_Form1()
  ui_login.setupUi(Form_login)
  Form_login.show()
  
  Form_chat = QtWidgets.QWidget()
  ui_chat = Ui_Form()
  ui_chat.setupUi(Form_chat)
  history = ''
  
  
  class listen_thread(QtCore.QObject):
      running = False
      listen_var = QtCore.pyqtSignal(str)
      def run():
          print('checkpoint')
          while True:
              listen_var.emit('message')
              QtCore.QThread.msleep(1000)
  
  def connect_pressed():
      username = ui_login.lineEdit.text()
      Form_login.hide()
      Form_chat.show()
      sock.connect(('127.0.0.1', 10000))
      
      thread = QtCore.QThread()
      listen1 = listen_thread()
      listen1.moveToThread(thread)
      listen1.listen_var.connect(update_chat_history)
      thread.started.connect(listen1.run)
      thread.start()
      
  
  @QtCore.pyqtSlot(str)
  def update_chat_history(message):
      print(message)
      ui_chat.textEdit_2.append(message) 
  
  def send_pressed():
      message = ui_login.lineEdit.text() + ' &gt; ' + ui_chat.lineEdit.text()
      sock.send(bytes(str(message),'utf-8'))
      # update_chat_history(message)
      ui_chat.lineEdit.setText('')
  
  
  def listen(some):
      while True:
          try:
              data = sock.recv(1024)
          except:
              pass
          else:
              update_chat_history(str(data))
  
  
  ui_login.pushButton.clicked.connect(connect_pressed)
  ui_chat.pushButton.clicked.connect(send_pressed)
  
  sys.exit(app.exec_())
  </code></pre>
  <p>When I'm launching it the output is:</p>
  <pre><code>QThread: Destroyed while thread is still running
  Aborted (core dumped)
  </code></pre>
  <p>Can somebody help???</p>