Solved QSqlDriver notification
-
Hello,
I would like to use a notifications of QSqlDriver when a value in the table (Count) has changed.I use Postgre.
code source :
if(!query.exec("Notify Count")) qDebug()<<query->lastError().text(); if(!m_db.driver()->subscribeToNotification("Count")) { qDebug()<<m_db.driver()->lastError().text(); m_db.close(); qApp->quit(); } connect(m_db.driver(), static_cast<void(QSqlDriver::*)(const QString &)>(&QSqlDriver::notification), [](const QString &name){qDebug("notification"); });
When the table is updated by another program, i don't receive a notification.
source code of the other program :
if(!query.exec("UPDATE Count SET Counter = Counter+1")) qDebug()<<)query.lastError().text();
Thank's
-
Hi
But you do get a notification if same program changes the db ? -
No, i haven't a notification
-
Did you check with HasFeature if it can do it ?
http://doc.qt.io/qt-5/qsqldriver.html#hasFeature -
qDebug()<<m_db.driver()->hasFeature(QSqlDriver::EventNotifications);
return true.
-
Super. it should work.
I dont have PostG. DB so can't play with itDoes the queries all work ?
Syntax looks odd to me but I guess its valid
https://www.postgresql.org/docs/9.0/static/sql-notify.html
Sorry, not sure how to test this further.
-
All query works, I don't know what to do
-
@Yacinoben
Hi
I would find some other tool to test if notification does indeed work.
So i know it must be something in my program or Qt.https://jdbc.postgresql.org/documentation/91/listennotify.html
-
up ?
I have tried everything, but nothing. -
it's solved. In postgre i wrote "CREATE RULE name AS ON UPDATE TO nameTable DO NOTIFY notification_name
https://www.postgresql.org/docs/8.1/static/rules-update.html