U sluit de databaseverbinding voordat de hoofdlus van Qt is gestart, verplaats alle Postgres-gerelateerde dingen naar de thread.
class ThreadClass(QtCore.QThread):
updateTable = pyqtSignal(dict)
def __init__(self, parent=None):
super().__init__()
def run(self):
conn = psycopg2.connect("dbname=motocompano_dev user=pg_admin password=pGsql_#--w3N_a0X!s7J-o1U+ host=localhost port=5555")
cur = conn.cursor()
cur.execute("select * from events")
orderbook = cur.fetchall()
for rowNum, rowData in enumerate(orderbook):
self.updateTable.emit({"insertRow": 0})
for colNum, data in enumerate(rowData):
self.updateTable.emit({"setItem": [rowNum, colNum, data]})
cur.close()
conn.close()