main.cpp#include <QApplication>#include "qmywidget.h"int main(int argc, char *argv[]){ QApplication app(argc, argv); QMyWidget wgt(0); return app.exec();}qmywidget.h#ifndef QMYWIDGET_H#define QMYWIDGET_H#include <QWidget>class QPlainTextEdit;class QPushButton;class QVBoxLayout;class QMyWidget : public QWidget{ Q_OBJECTprotected: virtual void closeEvent(QCloseEvent*);public: QMyWidget(QWidget * = 0); QPlainTextEdit *pTE; QPushButton *cmdNotify; QVBoxLayout *layout;public slots: void slotNotify(); void slotNotification(const QString &);};#endif // QMYWIDGET_Hqmywidget.cpp#include <QPlainTextEdit>#include <QPushButton>#include <QtSql>#include <QVBoxLayout>#include "qmywidget.h"QMyWidget::QMyWidget(QWidget *parent) : QWidget(parent){ pTE = new QPlainTextEdit(this); cmdNotify = new QPushButton("Notify", this); layout = new QVBoxLayout(); layout->addWidget(pTE); layout->addWidget(cmdNotify); setLayout(layout); QSqlDatabase db = QSqlDatabase::addDatabase("QPSQL7"); db.setDatabaseName("test"); db.setHostName("localhost"); db.setPort(***); db.setUserName(***); db.setPassword(***); if (!db.open()) { qDebug() << "Database opened: " << db.lastError(); } else { qDebug() << "Database error";} db.driver()->subscribeToNotification("n1"); connect(db.driver(), SIGNAL(notification(const QString&)), this, SLOT(slotNotification(const QString&)) ); connect(cmdNotify, SIGNAL(clicked()), this, SLOT(slotNotify())); show();}void QMyWidget::slotNotification(const QString &Notif) { pTE->appendPlainText(Notif);}void QMyWidget::slotNotify() { pTE->appendPlainText("Notify button pressed"); QSqlQuery queryNotify("NOTIFY n1;");}void QMyWidget::closeEvent(QCloseEvent *event) { QSqlDatabase db = QSqlDatabase::database(); if (db.isOpen()) { db.close(); }}
C++ (Qt)QMyWidget wgt;
CREATE TRIGGER name_of_trigger FOR some_tableAFTER UPDATE ASBEGIN NOTIFY n1;END
CREATE TRIGER trigg AFTER UPDATE ON table1 ASBEGIN NOTIFY n1;END
SQLCREATE RULE notify_some_table_update_rule AS ON UPDATE TO some_table DO NOTIFY some_table_updated;