Как сделать постоянный вызов accept, чтобы обновлять виджет QTextEdit?
Просто Thread не работает:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import requests
from threading import Thread
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setCentralWidget(QWidget(self))
self.lay = QVBoxLayout()
self.centralWidget().setLayout(self.lay)
self.initUI()
def initUI(self):
self.id = 'default'
self.idl = QLineEdit()
self.lay.addWidget(self.idl)
self.log = QPushButton()
self.log.setText('Connect')
self.log.clicked.connect(self.setId)
self.lay.addWidget(self.log)
self.board = QTextEdit()
self.board.textChanged.connect(self.send)
self.board.setMinimumSize(1200, 700,)
self.board.setStyleSheet('font-size:20px;')
self.lay.addWidget(self.board)
thread = Thread(target=self.accept)
thread.start()
def setId(self):
self.id = self.idl.text()
def send(self):
requests.get(f'http://localhost:8080/set/{self.id}/{self.board.toPlainText()}/...')
def accept(self):
self.board.setText(requests.get(f'http://localhost:8080/get/{self.id}/...').text)
if __name__ == '__main__':
app = QApplication([])
win = MainWindow()
win.show()
app.exec_()
Если делать так как описано выше, то возникает ошибка:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QTextDocument(0x104051140), parent's thread is QThread(0x100403ac0), current thread is QThread(0x10409a0a0)
Segmentation fault: 11