I have a websocket and want to update my PyQt5-GUI every time there is a new packet coming in.
There is a QAbstractTableModel to handle the conversion to the TableView.
A QWidget wraps up the TableView and Model. In this QWidget I started a thread to listen to the data from the socket and as args I gave it the update-function, that should update the data and the table.
FieldTableModel is my QAbstractTableModel. packet_to_fnc receives data from the socket, throws it in a dict and passes it into update_table().
class FieldTableWidget(QWidget):
    def __init__(self):
        super().__init__()
        self.field = Field(20)
        self.receiver = Thread(target=packet_to_fnc, args=(self.update_table,))
        self.receiver.start()
        self.table = QTableView()
        self.table.setModel(FieldTableModel(self.field))
        self.layout = QVBoxLayout()
        self.layout.addWidget(self.table)
        self.setLayout(self.layout)
    def update_table(self, packet):
        self.field.update_field(packet)
        self.table.setModel(FieldTableModel(self.field))
Now when I start the GUI and data from the socket comes in, I get the following message in the console for every packet:
QObject: Cannot create children for a parent that is in a different thread.
(Parent is QHeaderView(0x16b0b6f5590), parent's thread is QThread(0x16b06c2c7a0), current thread is QThread(0x16b0b7b4610)
So my problem basically is that PyQt doesn't like the execution of update_table() in the Thread.
I was also thinking of using a @property-attribute in a class, but I guess it's the same outcome?
Is there a different way to trigger the Table-Update every time there is new socket data?