title: Error with python program with pyqt5 and sqlite, Cannot create children for a parent that is in a different thread
body: <p>I make a program using pyqt5 and sqlite db.</p>
  <p>it's randomly select a db's row text and display in textbrowser widget and copy to clipboard each time i pushed a button.</p>
  <p>and with keyboard module, hooking the <kbd>ctrl</kbd>+<kbd>v</kbd> then check a label widget for repeat previous pushed button's function.</p>
  <p>But when i push <kbd>ctrl</kbd>+<kbd>v</kbd>, it's not working in Pycharm with this error message</p>
  <pre><code>Process finished with exit code -1073740791 (0xC0000409)
  </code></pre>
  <p>And when i run the code in terminal, again with this error message</p>
  <pre><code>QObject: Cannot create children for a parent that is in a different thread.
  (Parent is QTextDocument(0x207618a6770), parent's thread is QThread(0x2075f5acef0), current thread is QThread(0x20761d818d0)
  </code></pre>
  <p>i think maybe a thread problem. but i didn't use thread.
  It's my pyqt5 widget's ui image and my source code.</p>
  <p>How can i make this code working?</p>
  <p><img src="https://i.stack.imgur.com/uymG6.jpg" alt="ui image" /></p>
  <pre><code>import sys
  from PyQt5.QtWidgets import *
  from PyQt5 import uic
  import sqlite3
  import random
  import pyperclip
  import keyboard
  from time import sleep
  
  form_class = uic.loadUiType(&quot;exam.ui&quot;)[0]
  
  class WindowClass(QMainWindow, form_class) :
      def __init__(self) :
          super().__init__()
          self.setupUi(self)
          self.pb1.clicked.connect(self.bt1)
          self.pb2.clicked.connect(self.bt2)
          self.pb3.clicked.connect(self.bt3)
          self.pb4.clicked.connect(self.bt4)
          self.pb5.clicked.connect(self.bt5)
          self.con = sqlite3.connect(&quot;exam.db&quot;)
          self.cursor = self.con.cursor()
          keyboard.add_hotkey(&quot;ctrl+v&quot;, self.kt)
  
      def bt1(self):
          self.lb1.clear()
          self.tb.clear()
          self.lb1.setText(&quot;a&quot;)
          self.cursor.execute(&quot;SELECT max(rowid) FROM a&quot;)
          maxrow = self.cursor.fetchone()
          r = random.randrange(1, maxrow[0] + 1)
          self.cursor.execute(&quot;SELECT * FROM a WHERE rowid =?&quot;, (r,))
          t = self.cursor.fetchone()
          self.tb.setPlainText(t[0])
          pyperclip.copy(t[0] + &quot;\n&quot;)
  
      def bt2(self):
          self.lb1.clear()
          self.tb.clear()
          self.lb1.setText(&quot;b&quot;)
          self.cursor.execute(&quot;SELECT max(rowid) FROM b&quot;)
          maxrow = self.cursor.fetchone()
          r = random.randrange(1, maxrow[0] + 1)
          self.cursor.execute(&quot;SELECT * FROM b WHERE rowid =?&quot;, (r,))
          t = self.cursor.fetchone()
          self.tb.setPlainText(t[0])
          pyperclip.copy(t[0] + &quot;\n&quot;)
  
      def bt3(self):
          self.lb1.clear()
          self.tb.clear()
          self.lb1.setText(&quot;c&quot;)
          self.cursor.execute(&quot;SELECT max(rowid) FROM c&quot;)
          maxrow = self.cursor.fetchone()
          r = random.randrange(1, maxrow[0] + 1)
          self.cursor.execute(&quot;SELECT * FROM c WHERE rowid =?&quot;, (r,))
          t = self.cursor.fetchone()
          self.tb.setPlainText(t[0])
          pyperclip.copy(t[0] + &quot;\n&quot;)
  
      def bt4(self):
          self.lb1.clear()
          self.tb.clear()
          self.lb1.setText(&quot;d&quot;)
          self.cursor.execute(&quot;SELECT max(rowid) FROM d&quot;)
          maxrow = self.cursor.fetchone()
          r = random.randrange(1, maxrow[0] + 1)
          self.cursor.execute(&quot;SELECT * FROM d WHERE rowid =?&quot;, (r,))
          t = self.cursor.fetchone()
          self.tb.setPlainText(t[0])
          pyperclip.copy(t[0] + &quot;\n&quot;)
  
      def bt5(self):
          self.lb1.clear()
          self.tb.clear()
          self.lb1.setText(&quot;e&quot;)
          self.cursor.execute(&quot;SELECT max(rowid) FROM e&quot;)
          maxrow = self.cursor.fetchone()
          r = random.randrange(1, maxrow[0] + 1)
          self.cursor.execute(&quot;SELECT * FROM e WHERE rowid =?&quot;, (r,))
          t = self.cursor.fetchone()
          self.tb.setPlainText(t[0])
          pyperclip.copy(t[0] + &quot;\n&quot;)
  
      def kt(self):
          if self.lb1.text() == &quot;a&quot;:
              self.bt1()
          elif self.lb1.text == &quot;b&quot;:
              self.bt2()
          elif self.lb1.text == &quot;c&quot;:
              self.bt3()
          elif self.lb1.text == &quot;d&quot;:
              self.bt4()
          elif self.lb1.text == &quot;e&quot;:
              self.bt5()
      if __name__ == &quot;__main__&quot; :
          app = QApplication(sys.argv)
          myWindow = WindowClass()
          myWindow.show()
          app.exec_()
  </code></pre>
  <p><a href="https://drive.google.com/open?id=1u3rIzu5kuAPVIxSxGtKQUBtthOiDpVIk" rel="nofollow noreferrer">Db file link</a>
  <a href="https://drive.google.com/open?id=1pPkXjU9S883nXoABJIo2-UGLRuxxrG7y" rel="nofollow noreferrer">ui file link</a></p>
  <p>i just add a db and ui file.</p>