简体   繁体   English

如何使用 QT 和 C++ 侦听 mysql 数据库中的触发事件?

[英]How do I listen for a triggered event in mysql database using QT & C++?

I am currently developing a Quote Generator for the office where I work using C++, QT and MYSQL.我目前正在使用 C++、QT 和 MYSQL 为办公室开发报价生成器。 Ive mostly completed it, but I still consider myself a noob to C++ as I have not used it in years.我几乎完成了它,但我仍然认为自己是 C++ 的菜鸟,因为我已经多年没有使用它了。 Im using the QMYSQL driver and I have succesfully created this trigger in mysql database (CREATE TRIGGER new_quote_added AFTER INSERT ON quotes FOR EACH ROW INSERT INTO newquotes (quoteNUM, name) VALUES (NEW.quoteNUM, NEW.name)),我正在使用 QMYSQL 驱动程序,并且我已成功在 mysql 数据库中创建了此触发器(在每行插入引号后创建触发器new_quote_added quotes (quoteNUM,name)VALUES(NEW.quoteNUM,NEW.name)),

Im wondering if someone can give me some examples of how I can set up a listener to see this trigger and then publish a message to my systemtrayIcon that I have set up.我想知道是否有人可以给我一些示例,说明如何设置侦听器以查看此触发器,然后将消息发布到我设置的 systemtrayIcon。 My apologies if this is super basic but as I said Im new and havent found anyone else doing quite this.如果这是超级基本的,我深表歉意,但正如我所说,我是新手,还没有发现其他人这样做。 Thank you in advance for your help预先感谢您的帮助

MySQL has no Notify/Subscribe mechanism, unlike Postgres.与 Postgres 不同,MySQL 没有通知/订阅机制。 So, you need to do polling on your desired table to keep track of inserts.因此,您需要对所需的表进行轮询以跟踪插入。 You may also take a look at this implementation: https://github.com/Cyclonecode/mysql-notification It's creating an Http server and it sends notifications over a WebSocket connection.你也可以看看这个实现: https://github.com/Cyclonecode/mysql-notification它正在创建一个 Http 服务器并通过 Z45EDC1B96407D9D213DD1135962A32A 连接发送通知。 It would not fit into every use case because of lacking security considerations.由于缺乏安全考虑,它并不适合所有用例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM