-2

Code:

class MainWindow(QMainWindow):

  def __init__(self):
    super().__init__()
    self.initUI()
  def initUI(self):
    self.textEdit_3 = QtWidgets.QTextEdit()
    self.textEdit_3.setGeometry(QtCore.QRect(390, 40, 451, 441))
    self.textEdit_3.setReadOnly(True)
    self.textEdit_3.setObjectName("textEdit_3")
    font = QtGui.QFont()
    font.setPointSize(13)
    self.textEdit_3.setFont(font)
    self.r()
    self.setGeometry(600, 100, 1000, 900)
    self.setWindowTitle('Scroll Area Demonstration')
    self.show()
  def r(self):
    self.vaa = Thread(target=self.update1)
    self.vaa.start()
  def update1(self):
    self.textEdit_3.insertPlainText('test')
def main():
  app = QtWidgets.QApplication(sys.argv)
  main = MainWindow()
  sys.exit(app.exec_())

if __name__ == '__main__':
    main()

ERROR : QObject::connect: Cannot queue arguments of type 'QTextCursor' (Make sure 'QTextCursor' is registered using qRegisterMetaType().)

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Apart from anything else, you appear to be updating a GUI object (the `QTextEdit`) from a secondary thread. That's not supported. – G.M. Apr 06 '20 at 13:38

1 Answers1

0

You cannot add text directly from another thread to a QTextEdit (or to another GUI element) but you must use tokens and other elements that are thread-safe:

class MainWindow(QMainWindow):
    updateText = QtCore.pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.initUI()

        self.updateText.connect(self.textEdit_3.insertPlainText)

    # ...

    def update1(self):
        self.updateText.emit("test")
eyllanesc
  • 235,170
  • 19
  • 170
  • 241