Is there any qt signal for sql database change?

后端 未结 2 806
死守一世寂寞
死守一世寂寞 2020-12-16 06:57

I wrote a C++ program using Qt. some variables inside my algorithm are changed outside of my program and in a web page. every time the user changes the variable values in th

相关标签:
2条回答
  • 2020-12-16 07:25

    There is no such thing. The Qt event loop and the database are not connected in any way. You only fetch/alter/delete/insert/... data and that's it. Option 1 is the one you have to do. There are ways to use TRIGGER on the server side to launch external scripts but this would not help you very much.

    0 讨论(0)
  • 2020-12-16 07:33

    QSqlDriver supports notifications which emit a signal when a specific event has occurred. To subscribe to an event just use QSqlDriver::subscribeToNotification( const QString & name ). When an event that you’re subscribing to is posted by the database the driver will emit the notification() signal and your application can take appropriate action.

    db.driver()->subscribeToNotification("someEventId");
    

    The message can be posted automatically from a trigger or a stored procedure. The message is very lightweight: nothing more than a string containing the name of the event that occurred.

    You can connect the notification(const QString&)signal to your slot like:

    QObject::connect(db.driver(), SIGNAL(notification(const QString&)), this, SLOT(refreshView()));
    

    I should note that this feature is not supported by MySQL as it does not have an event posting mechanism.

    0 讨论(0)
提交回复
热议问题