[Qgis-user] Updating a custom table in plugin from Postgres

Raúl Sangonzalo Terrado raulsangonzalo at gmail.com
Fri Dec 7 04:24:51 PST 2018


Hi,

in relation to what I posted in
https://gis.stackexchange.com/questions/305219/qgis-3-python-plugin-psycopg2-postgres-notify-listen-live-connection
I'm having the following problem:

I have a plugin with a table in a dock widget to allocate tasks to other
users. The list of tasks (to be allocated by supervisors) is displayed in
the table by:

- Psycopg2: query the table in my postgres database. I do a cur.fetchall()
so I retrieve all the items in a list.
- QTableWidget: I run two 'for' loops to insert all the rows. After this, I
change the formatting to some columns, etc.

Up to this point everything is working well, absolutely functional.

The Problem:

I want to set up an open connection with a "LISTEN" channel so when any
cell is modified within the table, I run a postgres trigger and the table
UPDATES (hence, the script runs again and the table is re-created).

I couldn't manage to allocate this signal within my python script to the
Task Manager to run in the background - because the python script runs in
the main thread the QGIS gets frozen, waiting forever for the NOTIFY signal.

The only solution I found was to add the table itself to QGIS and use the
new built-in function for listening notifications in layers. This works
perfect, as I link it to run an action to re-run the table. The only
problem is that I will always need to have the table added as a layer.

So my question is if I could use the same built-in connection in QGIS with
my plugin, without having to be set up in a layer necessarily.

Hope this makes sense.
Thanks,
Raúl

PS: Another example: within the same philosophy, having a chat plugin in a
widget will need to have a LISTEN channel always open, and having the "chat
table" in the project doesn't seem right at all!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20181207/9c44837d/attachment.html>


More information about the Qgis-user mailing list