Qt 项目主进程接收Alarm 后在GUI上显示,并且可以有选择性输出文件
程序员文章站
2022-10-20 10:37:12
项目主进程接收报警后,将alarm msg 发送给代理, 并将其分发: 代理将其分发后GUI接收此alarm, 并且将其在独立窗口显示: 独立窗口代码如此,并且点击窗口上的confirm按钮,可以将其输出文件保存: ......
项目主进程接收报警后,将alarm msg 发送给代理, 并将其分发:
else if (msg.name == "MesLCUalarmRep") { QString errorText; QXmlTools tool; int status; int code; int severity; if ( tool.setData(msg.body, errorText) ) { QDomElement root = tool.getDocument()->documentElement(); QString tag = root.tagName(); if ( tag == "Body" ) { QDomNode child = root.firstChild(); while ( !child.isNull() ) { tag = child.toElement().tagName(); if ( tag == "STAT" ) { QString text_status = child.toElement().text(); if( text_status == "MesInfo" ){ //return; } status = ( text_status.toUpper() == "MESON" ) ? 1 : 0; } else if ( tag == "ErrorType" ) { severity = ( child.toElement().text().toUpper() == "HEAVY" ) ? 1 : 0; } else if ( tag == "ErrorMessage" ) { errorText = child.toElement().text(); } else if ( tag == "ErrorCode" ) { code = atoi( child.toElement().text().toLatin1().data() ); } child = child.nextSibling(); } if(code == COMMONDEFECTALARMCODE || code == GLASSBROKENCALLCODE) { debug("enter common defect judge insertAlarm [%d] waitAlarmList.size:[%d]",code, waitAlarmList.size()); switchAlarmCode(code); } sendAlarmDetail2GUI(errorText);
/** *@projectName BoeB9Project *@author Hasan **/ void BoeB9QtmCellInlineMain::sendAlarmDetail2GUI(QString errorMsg) { mgrGlassMapCellInlineBoeB9Lst& GlassMapLst = mgrGlassMapCellInlineBoeB9Lst::GetInstance(); QString diffMsg = "4H"; QString errorTIme = QDateTime::currentDateTime().toString("yyyyMMdd-hh:mm:ss"); QString errorGls = GlassMapLst.GetJobGlassFromkey("GlsID"); if(errorGls == "") errorGls = "9AAB85001702a1"; else if(errorGls.size()<14 && errorGls != "") errorGls.append(" "); errorMsg = diffMsg + errorTIme + errorGls + errorMsg; sendMesGUIOperatorCallMsg(errorMsg); }
代理将其分发后GUI接收此alarm, 并且将其在独立窗口显示:
void BoeB9InlineMainForm::showOperatorCallMsg(QString msg) { if(msg.startsWith("4H")) showAlarmList(msg); else { opCallDialog->insertMassge(msg); opCallDialog->show(); } }
void BoeB9InlineMainForm::showAlarmList(QString alarmMsg) { alarmListForm->addAlarmItem2List(alarmMsg.mid(2, alarmMsg.size()-1)); alarmListForm->show(); }
独立窗口代码如此,并且点击窗口上的confirm按钮,可以将其输出文件保存:
#include "alarmlistform.h" #include "ui_alarmlistform.h" #include <QMessageBox> AlarmListForm::AlarmListForm(QWidget *parent, Qt::WindowFlags) : QWidget(parent), ui(new Ui::AlarmListForm), currentRow(-1) { ui->setupUi(this); setWindowTitle("Alarm List"); QString currentDay = QDateTime::currentDateTime().toString("yyyy-MM-dd"); QString filePath = SMCU_WORK_PATH "/"; filePath += currentDay; filePath += "-alarmList.dat"; file = new QFile(filePath); } AlarmListForm::~AlarmListForm() { delete ui; } void AlarmListForm::addAlarmItem2List(QString alarmMsg) { QListWidgetItem *item = new QListWidgetItem; item->setText(alarmMsg); ui->listWidget->addItem(item); } void AlarmListForm::on_pushButton_clicked() { if(currentRow < 0) return; showDetailAlarm(currentRow); currentRow = -1; } void AlarmListForm::on_listWidget_clicked(const QModelIndex &index) { currentRow = ui->listWidget->currentRow(); } void AlarmListForm::on_pushButton_2_clicked() { int count = ui->listWidget->count(); for(int index = count; index >= 0; index --) { QListWidgetItem *item = ui->listWidget->takeItem(index); delete item; } this->close(); } void AlarmListForm::on_listWidget_doubleClicked(const QModelIndex &index) { showDetailAlarm(ui->listWidget->currentRow()); } void AlarmListForm::showDetailAlarm(int row) { QListWidgetItem *item = ui->listWidget->item(row); QString alarmDetail = item->text(); int ans = QMessageBox::question(this, tr("Alarm Detail"), tr(alarmDetail.toLatin1().data()), QMessageBox::Save | QMessageBox::Cancel); if(ans == QMessageBox::Save) { saveAlarm2File(alarmDetail); delete item; } } void AlarmListForm::saveAlarm2File(QString alarmMsg) { if(!file->isOpen()) { if(file->open(QIODevice::Append | QIODevice::Text)) { } else { return; } } if(alarmMsg.size() <= 10) { QTextStream buff(file); buff<<"<Time>" << "alarmMsg.left(10)" << "</Time>"; return; } QTextStream buff(file); buff<<"<Time>" << alarmMsg.mid(0, 17) << "</Time>"; buff<<"<GlsID>" << alarmMsg.mid(17, 14) << "</GlsID>"; buff<<"<AlarmMsg>" << alarmMsg.mid(31, alarmMsg.size()-1) << "</AlarmMsg>"; buff<<endl; buff.flush(); file->close(); }
上一篇: 信守合同
下一篇: 你做的最后悔的事是什么?