In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to write Qt data query". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to write Qt data query.
I. Preface
The data query module is the least difficult in the whole system. Because Qt encapsulates the database operation perfectly, all kinds of queries are easy and effortless. Qt built-in sqlite database, you can find in the database plug-in directory sqldrivers qsqlite.dll file is relatively large, about 800KB, and qsqlmysql.dll just 70KB, according to reason mysql must be bigger than sqlite, later access to information found that the more Qt source code has been included in the sqlite source code, directly built into the compilation. This makes it very convenient for users to use the sqlite database, unlike other databases such as mysql, which also need to bring the dynamic library files of the corresponding database. In fact, Android also uses a lot of sqlite database, which shows how convenient the sqlite database is. The database communication in Qt is all in the qtsql module. The two classes commonly used are qsqlquery and qsqltablemodel. One is used to execute sql statements. Qsqlquery literally means query. In fact, it also includes adding, deleting and modifying (basic terms are abbreviated as additions, deletions and modifications). Anyway, he can execute arbitrary sql statements. As long as the database supports it, if a result is returned, it will provide a result set return. You can loop through the results. The code is as follows:
/ / start database transaction QSqlDatabase::database () .transaction (); int count = sqls.count (); for (int I = 0; I
< count; i++) { QSqlQuery query; query.exec(sqls.at(i));}//提交数据库事务bool ok = QSqlDatabase::database().commit();if (!ok) { QSqlDatabase::database().rollback();} 第三点数据库翻页,由于经常做数据库相关的项目,其实大部分的项目,注意只要是项目不是那种调试工具级别的小demo,多多少少都会涉及到记录存储等,这就需要用到数据库,记录查询这块,少不了分页显示查询结果,不管是何种开发语言,各种程序员都会封装自己的一套通用的数据库翻页代码,毫无疑问我也封装了一套轮子,重复利用,我甚至封装了上一页下一页按钮+当前记录数等标签的功能,只要传入对应控件的指针即可,此代码开源。 二、功能特点 采集数据端口,支持串口端口+网络端口,串口支持自由设置串口号+波特率,网络支持自由设置IP地址+通讯端口,每个端口支持采集周期,默认1秒钟一个地址,支持设置通讯超时次数,默认3次,支持最大重连时间,用于重新读取离线的设备。 控制器信息,能够添加控制器名称,选择控制器地址+控制器型号,设置该控制器下面的探测器数量。 探测器信息,能够添加位号,可自由选择探测器型号,气体种类,气体符号,高报值,低报值,缓冲值,清零值,是否启用,报警声音,背景地图,存储周期,数值换算小数点位数,报警延时时间,报警的类型(HH,LL,HL)等。 控制器型号+探测器型号+气体种类+气体符号,均可自由配置。 地图支持导入和删除,所有的探测器对应地图位置可自由拖动保存。 端口信息+控制器信息+探测器信息,支持导入导出+导出到excel+打印。 运行记录+报警记录+用户记录,支持多条件组合查询,比如时间段+控制器+探测器等,所有记录支持导出到excel+打印。 导出到excel的记录支持所有excel+wps等表格文件版本,不依赖excel等软件。 可删除指定时间范围内的数据,支持自动清理早期数据,设置最大保存记录数。 支持报警短信转发,支持多个接收手机号码,可设定发送间隔,比如即时发送或者6个小时发送一次所有的报警信息,短信内容过长,自动拆分多条短信。 支持报警邮件转发,支持多个接收邮箱,可设定发送间隔,比如即时发送或者6个小时发送一次所有的报警信息,支持附件发送。 高报颜色+低报颜色+正常颜色+0值颜色+曲线背景+曲线颜色等,都可以自由选择。 软件的中文标题+英文标题+logo路径+版权所有都可以自由设置。 提供开关设置开机运行+报警声音+自动登录+记住密码等。 报警声音可设置播放次数,界面提供17种皮肤文件选择。 支持云端数据同步,可设置云端数据库的信息,比如数据库名称,用户名+密码等。 支持网络转发和网络接收,网络接收开启后,软件从udp接收数据进行解析。网络转发支持多个目标IP,这样就实现了本地采集的软件,自由将数据转到客户端,随时查看探测器数据。 自动记住用户最后停留的界面+其他信息,重启后自动应用。 报警自动切换到对应的地图,探测器按钮闪烁。 双击探测器图标,可以进行回控。 支持用户权限管理,管理员+操作员两大类,用户登录+用户退出,可以记住密码和自动登录,超过三次报错提示并关闭程序。 支持四种监控模式,设备面板监控+地图监控+表格数据监控+曲线数据监控,可自由切换,四种同步应用。 支持报警继电器联动,一个位号可以跨串口联动多个模块和继电器号,支持多对多。 本地数据存储支持sqlite+mysql,支持远程数据同步到云端数据库。自动重连。 本地设备采集到的数据实时上传到云端,以便手机APP或者web等其他方式提取。 支持两种数据源,一种是串口和网络通过协议采集设备数据,一种是数据库采集。数据库采集模式可以作为通用的系统使用。 自带设备模拟工具,支持16个设备数据模拟,同时还带数据库数据模拟,以便在没有设备的时候测试数据。 默认通信协议采用modbus协议,后期增加mqtt等物联网协议的支持,做成通用系统。 支持所有windows操作系统+linux操作系统和其他操作系统。 三、效果图 四、核心代码void frmDataNode::initData(){ whereSql = "where 1=1"; columnNames btnFirst, ui->BtnPre, ui- > btnNext, ui- > btnLast, "LogID"); dbPage- > setWhereSql (whereSql); dbPage- > select ();} void frmDataNode::on_btnSelect_clicked () {QDateTime dateStart = ui- > dateStart- > dateTime (); QDateTime dateEnd = ui- > dateEnd- > dateTime (); if (dateStart > dateEnd) {QUIHelper::showMessageBoxError ("start time cannot be greater than end time!", 3); return } / / build the SQL statement QString sql = "where 1room1"; if (ui- > ckTimeStart- > isChecked ()) {if (App::LocalDBType.toUpper () = = "SQLITE") {sql + = "and datetime (SaveTime) > ='" + dateStart.toString ("yyyy-MM-dd HH:mm:ss") + "'" Sql + = "and datetime (SaveTime) = unix_timestamp ('" + dateStart.toString ("yyyy-MM-dd HH:mm:ss") + "')"; sql + = "and unix_timestamp (SaveTime)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.