Using Psycopg2 And Qthreads Together(or Just Postgresql And Qthreads) And Updating Gui
The orderbook in DB always shows the right orderbook, i just want to continually update it in a GUI. I've been trying to get this to work but when i try to run a cur statement the
Solution 1:
You are closing the database connection before Qt's main loop is started, move all Postgres related stuff into the 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()
Post a Comment for "Using Psycopg2 And Qthreads Together(or Just Postgresql And Qthreads) And Updating Gui"