Qt|Qt TCP/IP C++ 数据库 历史数据操作部分

Qt TCP/IP C++ 数据库 历史数据操作部分
(1)对历史数据的查询操作。采样数据存储在数据库里,通过时间标签可以查询到之前存储的历史数据;

//查询 TimeTemp=ui->lineEdit->text().trimmed(); QSqlQuery *sqlQuery=new QSqlQuery(db); QString command = QString("SELECT RtuName,TimeLabelStart,TimeLabelEnd," "Data FROM RTU WHERE TimeLabelStart='%1' AND" "RtuName='%2'; ").arg(TimeTemp).arg(RTUNOTemp); //判断查询是否成功 if(!sqlQuery->exec(command)) { ui->label_2->setText("data base check failed!"); }else { //若查询成功,将数据调出查看 while(sqlQuery->next()) { NetData1= sqlQuery->value(3).toString(); ReData1=NetData1.split(","); ui->label_2->setText("data base check successfully!"); for (int i=0; i<100; i++) x[i]=ReData1.at(i).toDouble(); LinePlotter->curve(x,100); //呈现在表中 } }

【Qt|Qt TCP/IP C++ 数据库 历史数据操作部分】(2)对历史数据的删除操作。通过时间标签可以删除相应的历史数据;
//删除 LinePlotter->clearCurve(0); //首先将图表中的曲线删除 TimeTemp=ui->lineEdit->text().trimmed(); QSqlQuery *sql=new QSqlQuery(db); //SQL删除语言 QString command = QString("DELETE FROM RTU WHERE TimeLabelStart='%1' " "AND RtuName='%2'; ").arg(TimeTemp).arg(RTUNOTemp); //判断数据是否删除成功 if(!sql->exec(command)) { //QMessageBox::information(this,"Title","delete failed!"); ui->label_2->setText("delete failed!"); }else { //QMessageBox::information(this,"Title","delete successfully!"); ui->label_2->setText("delete successfully!"); }

    推荐阅读