Qt 项目主进程接收Alarm 后在GUI上显示,并且可…
2018-06-17 20:28:23来源:未知 阅读 ()
项目主进程接收报警后,将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(); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
下一篇:C/C++ -- 插入排序算法
- 分享一个自己项目中用到的c++版的日志类(对初学者十分有用的 2020-05-22
- CreateEvent进程同步 2020-04-19
- C++ 进程和匿名管道使用学习 2020-01-14
- 开源项目SMSS开发指南(二)——基于libevent的线程池 2020-01-11
- Visual Studio 重命名项目名 2019-12-06
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash