折扣爆料
折扣好货实时更新
数据库请求是在数据库采集的基础上,换成http请求的形式来获取数据,这样就脱离了数据库组件,而采用的通用的http请求的形式从数据库拿数据库,这个通用性就非常广泛了,比如对方用java采集到设备的数据存入数据库,另外一个区域是用的c#采集的数据入库,然后统一规则统一规范约定一个请求机制,定时器或者线程取执行请求,拿到的json数据,挨个取出来结果,数组集合的方式发信号出去。
之前写过的可视化大屏电子看板程序,采用的也是http请求数据库采集的方式拿数据展示,需要多方协作,至于数据库中的数据是谁放的,和大屏程序本身无关,对应既可以是请求的形式存入的数据,也可以是直接数据库写入的方式,即可以是java也可以是c#,大屏UI展示只管取出数据按照规则展示即可,要多漂亮就多漂亮,qss和painter在手,心中有坐标,万物皆painter。
关于Qt数据库相关开发的一些经验总结:
https://qtchina.blog.csdn.net/article/details/119022424
#include "frmdbhttp.h"
#include "ui_frmdbhttp.h"
#include "quihelper.h"
#include "dbhelper.h"
#include "dbhttpthread.h"
frmDbHttp::frmDbHttp(QWidget *parent) : QWidget(parent), ui(new Ui::frmDbHttp)
{
ui->setupUi(this);
this->initForm();
this->initConfig();
this->initTable();
}
frmDbHttp::~frmDbHttp()
{
delete ui;
}
void frmDbHttp::showEvent(QShowEvent *)
{
static bool isShow = false;
if (!isShow) {
isShow = true;
QTimer::singleShot(100, this, SLOT(on_btnStart_clicked()));
}
}
void frmDbHttp::initForm()
{
ui->frame->setFixedWidth(AppConfig::RightWidth);
QUIHelper::initTableView(ui->tableWidget);
maxCount = 100;
currentCount = 0;
timer = new QTimer(this);
timer->setInterval(1000);
connect(timer, SIGNAL(timeout()), this, SLOT(on_btnDo_clicked()));
//实例化网络请求采集数据通信类
dbHttp = new DbHttpThread(this);
connect(dbHttp, SIGNAL(debug(QString)), this, SLOT(debug(QString)));
connect(dbHttp, SIGNAL(error(QString)), this, SLOT(error(QString)));
connect(dbHttp, SIGNAL(receiveData(QString, QStringList, int)), this, SLOT(receiveData(QString, QStringList, int)));
//设置参数
dbHttp->setUrl("http://127.0.0.1:6000");
QMap<QString, QString> tables;
tables.insert("NodeData", "PositionID,NodeValue,NodeStatus,SaveTime");
dbHttp->setTables(tables);
}
void frmDbHttp::initConfig()
{
}
void frmDbHttp::saveConfig()
{
}
void frmDbHttp::initTable()
{
QStringList columnNames;
columnNames << "位号" << "当前值" << "状态" << "时间";
QList<int> columnWidths;
columnWidths << 160 << 100 << 100 << 220;
columnCount = columnNames.count();
ui->tableWidget->setColumnCount(columnCount);
ui->tableWidget->setHorizontalHeaderLabels(columnNames);
for (int i = 0; i < columnCount; i++) {
ui->tableWidget->setColumnWidth(i, columnWidths.at(i));
}
}
void frmDbHttp::debug(const QString &msg)
{
QUIHelper::appendMsg(ui->txtMain, 0, msg, maxCount, currentCount);
}
void frmDbHttp::error(const QString &msg)
{
QUIHelper::appendMsg(ui->txtMain, 1, msg, maxCount, currentCount);
}
void frmDbHttp::receiveData(const QString &tag, const QStringList &data, int msec)
{
QString msg = QString("用时( %1 秒) 标识( %2 ) 数据( %3 )").arg(QString::number((double)msec / 1000, f , 3)).arg(tag).arg(data.join("|"));
QUIHelper::appendMsg(ui->txtMain, 3, msg, maxCount, currentCount);
//显示到表格中
int count = data.count();
ui->tableWidget->setRowCount(count / columnCount);
int row = -1;
for (int i = 0; i < count; i = i + columnCount) {
row++;
for (int j = 0; j < columnCount; ++j) {
ui->tableWidget->setItem(row, j, new QTableWidgetItem(data.at(i + j)));
}
}
}
void
frmDbHttp::on_btnDo_clicked()
{
dbHttp->select("NodeData", "PositionID,NodeValue,NodeStatus,SaveTime");
}
void
frmDbHttp::on_btnStart_clicked()
{
if (ui->btnStart->text() == "启动服务") {
on_btnDo_clicked();
timer->start();
ui->btnStart->setText("停止服务");
} else {
timer->stop();
ui->btnStart->setText("启动服务");
}
}
void
frmDbHttp::on_btnClear_clicked()
{
QUIHelper::appendMsg(ui->txtMain, 0, "", maxCount, currentCount);
}