QT LINUX环境ETH 防呆程式

ETH_TEST.PRO SOURCE CODE:

#-------------------------------------------------
#
# Project created by QtCreator 2018-07-05T07:59:05
#
#-------------------------------------------------
 
QT       += core gui
 
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
 
TARGET = ETH_TEST
TEMPLATE = app
 
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
 
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
 
 
SOURCES += \
        main.cpp \
        eth_test.cpp
 
HEADERS += \
        eth_test.h
 
FORMS += \
        eth_test.ui
RC_FILE=icon.rc
 

ETH_TEST.H SOURCE CODE:

#ifndef ETH_TEST_H
#define ETH_TEST_H
 
#include <QMainWindow>
#include <QFile>
#include <QIODevice>
#include <QString>
#include <QDebug>
#include <QDebug>
#include <QTextStream>
#include <QDialog>
//#include <QWidget>
#include <stdio.h>
#include <iostream>
#include <QtGui>
#include <QMessageBox>
#include <QTableWidget>
#include <QStringList>
#include <QTimer>
#include <QStringList>
#include <QTextCodec>
#include <QCloseEvent>
#include <QProcess>
#include <QThread>
#include <QBrush>
#include <QColor>
#include <QDateTime>
#include <iostream>
#include <QFile>
 
namespace Ui {
class ETH_TEST;
}
 
class ETH_TEST : public QMainWindow
{
    Q_OBJECT
 
public:
    explicit ETH_TEST(QWidget *parent = 0);
    ~ETH_TEST();
protected:
    void closeEvent(QCloseEvent *);
private:
    Ui::ETH_TEST *ui;
    QTimer *m_timer=new QTimer(this);
    QTimer *EndWin=new QTimer(this);
    QTimer *RunWin=new QTimer(this);
    QTimer *TesttoCheck=new QTimer(this);
    double EveryprogressValues=0.0;//每次进度条增长值
    double progressTotalValues=0.0;//进度条执行总值
    int SetprogressTotalValues=0;//设置进度最大值
    int secondnumber=0;
    int Callen=0; //读取算率行数
    int Temlen=0;//读取温度行数
    QStringList ConfiArgc;
    QStringList Calcalate_rate_Value;//算率值
    QStringList Temperature_Value;//温度值
    bool IsAllStatePas=true;//所有数据状态
    QProcess *process=new QProcess;
    bool IsNotTime=false;
private slots:
    bool ReadCfgInfo(QString FileName);
    void InitialTableSlot();
    void StartQProgressBarSlot(int runtimer);
    void timernumber();
    void StartSupportForChinese();
    bool CallAnExternalProgram(QString exe);
    void start_read_output();
    void start_read_err_output();
    void Close_WndFailSlot();
    void Close_WndPassSlot();
    void finish_process(int exitCode,QProcess::ExitStatus exitStatus);
    void sleepslot(unsigned int msec);
    void ProcessSortStrSlot();//处理文本框中的字符串
    void FillTableData(QString str,int Item);//填充表格内数据
    void TestFailSlot();
    void SaveTestData();
    void InitialDelFile();
    void ProcessKill();
    void SleepWaitSlot();
    void IsNotbootProcessSlot();
};
 
#endif // ETH_TEST_H
 

ETH_TEST.CPP SOURCE CODE:

#include "eth_test.h"
#include "ui_eth_test.h"
#include <QPalette>
#include <QColor>
 
ETH_TEST::ETH_TEST(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::ETH_TEST)
{
    ui->setupUi(this);
    this->IsNotbootProcessSlot();
    if(ReadCfgInfo("config.ini")==true)
    {
        this->ProcessKill();
        InitialDelFile();//初始化删除Make文件
        InitialTableSlot();//初始化表格
        StartSupportForChinese();//启动Qt对中文支持
        //this->Callen=QString(this->ConfiArgc[3]).toInt();//设置取消读取的数据轮数
 
        //启动进度条
        StartQProgressBarSlot(QString(ConfiArgc[0]).toInt());//启动计时器
        if(CallAnExternalProgram(QString(ConfiArgc[1]))==false)//启动脚本
        {
            QObject::connect(EndWin,SIGNAL(timeout()),this,SLOT(close()));//启动报错程式退出
            EndWin->start(1000);
        }
        QObject::connect(RunWin,SIGNAL(timeout()),this,SLOT(ProcessSortStrSlot()));//处理文本框中的字符串
        RunWin->start(4000);
        QObject::connect(RunWin,SIGNAL(timeout()),this,SLOT(Close_WndPassSlot()));//启动退出窗体
        RunWin->start(100);
        QObject::connect(TesttoCheck,SIGNAL(timeout()),this,SLOT(TestFailSlot()));//测试过程检查
        TesttoCheck->start(200);
    }
    else
    {
        QObject::connect(EndWin,SIGNAL(timeout()),this,SLOT(Close_WndFailSlot()));//启动退出窗体
        EndWin->start(100);
    }
}
 
ETH_TEST::~ETH_TEST()
{
    delete ui;
}
 
void ETH_TEST::IsNotbootProcessSlot()
{
    QProcess *poc=new QProcess;
    poc->execute("ps -A > sample ");
}
 
void ETH_TEST::SleepWaitSlot()
{
    long nowtime=QDateTime::currentDateTime().toString("yyyyMMddhhmmss").toLong();
    long SetDateTime=(QDateTime::currentDateTime().toString("yyyyMMddhhmmss").toLong())+(QString(this->ConfiArgc[6]).toLong())+1;
    while(nowtime<SetDateTime)
    {
        nowtime=QDateTime::currentDateTime().toString("yyyyMMddhhmmss").toLong();
    }
    //QMessageBox::information(this,"",QString::number(nowtime));
}
 
void ETH_TEST::sleepslot(unsigned int msec)//延时
{
    QTime dieTime=QTime::currentTime().addMSecs(msec);
    while(QTime::currentTime()<dieTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents,100);
}
 
void ETH_TEST::ProcessKill()
{
    QString cmd="pkill "+QString(this->ConfiArgc[7]);
    //QMessageBox::information(this,"",cmd);
    QProcess ps;
    ps.execute(cmd);
    ps.close();
}
 
 
void ETH_TEST::InitialDelFile()//初始化删除MARK
{
    QFile file1("pass.txt");
    QFile file2("fail.txt");
    if(file1.exists())file1.remove();
    if(file2.exists()) file2.remove();
}
 
void ETH_TEST::SaveTestData()//保存测试数据
{
    QFile file(QDateTime::currentDateTime().toString("yyyyMMddhhmmsszzzz")+".txt");//设置名称
    file.open(QFile::WriteOnly|QFile::Text);
    QTextStream stream(&file);//定义文件写入流
    foreach (QString calc, this->Calcalate_rate_Value)
    {
        stream<<calc<<endl;
    }
    foreach (QString Temp, this->Temperature_Value)
    {
        stream<<Temp<<endl;
    }
    file.close();
}
 
void ETH_TEST::TestFailSlot()//侦测FAIL处理机制
{
    if(this->IsAllStatePas==false)
    {
        this->RunWin->stop();
        this->EndWin->stop();
        QFile file("fail.txt");
        file.open(QFile::WriteOnly|QFile::Text);
        file.close();
        this->SaveTestData();//存储测试数据
        //QThread::sleep(QString(ConfiArgc[6]).toInt());//延时退出
        if(process)//关闭进程
        {
            process->close();
            //delete process;
            //process=0;
        }
        this->ProcessKill();
        this->SleepWaitSlot();
        qApp->exit(1);
        //this->close();
    }
}
 
void ETH_TEST::Close_WndPassSlot()//关闭窗体PASS
{
    if((this->secondnumber)<=0)
    {
        QFile file("pass.txt");
        file.open(QFile::WriteOnly|QFile::Text);
        file.close();
        this->SaveTestData();//存储测试数据
        //QThread::sleep(QString(ConfiArgc[6]).toInt());//延进退出
        //this->close();
        this->ProcessKill();
        this->SleepWaitSlot();
        qApp->exit(1);
    }
}
void ETH_TEST::Close_WndFailSlot()//关闭窗体FAIL
{
    QMessageBox::information(this,"System Err",QString::fromLocal8Bit("配置文件打开读取错误!!"));
    QFile file("fail.txt");
    file.open(QFile::WriteOnly|QFile::Text);
    file.close();
    if(process)//关闭进程
    {
        process->close();
        //delete process;
        //process=0;
    }
    this->SaveTestData();//存储测试数据
    //QThread::sleep(QString(ConfiArgc[6]).toInt());//延进退出
    //this->close();
    this->ProcessKill();
    this->SleepWaitSlot();
    qApp->exit(1);
}
 
bool ETH_TEST::ReadCfgInfo(QString FileName)//读取配置
{
    QStringList lines;
    //QString Path=QDir::currentPath()+"/"+FileName;//读取当前目录路径
    QString Path=FileName;
    QFile file(Path);//设置打开文件的路径
 
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))//文件打开方式 
        return false;
    QTextStream stream(&file);
    QString line;
    while(!(line=stream.readLine()).isNull())//判断读取的内容是否为空l
    {
        QStringList Temp=line.split("=",QString::SkipEmptyParts);//截取字符串
        this->ConfiArgc.append(Temp[1]);
     }
     file.close();
     return true;
}
 
void ETH_TEST::InitialTableSlot()//初始化表格d
{
    ui->label_2->setText("");//设置label_2为空
    ui->cmdEdit->setReadOnly(true);//设置cmdEdit为只读编辑器
 
    ui->m_CounttableWidget->setEditTriggers(QAbstractItemView::NoEditTriggers);//禁至编辑表格
    ui->m_CounttableWidget->setSelectionBehavior(QAbstractItemView::SelectRows);//设置表格为整行选中
    ui->m_CounttableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);//允许多行选中
 
    //初始化界面
    QStringList HStrList;
    //HStrList.push_back(QString("NO."));
    HStrList.push_back(QString("GPU_0"));
    HStrList.push_back(QString("GPU_1"));
    HStrList.push_back(QString("GPU_2"));
    HStrList.push_back(QString("GPU_3"));
    HStrList.push_back(QString("GPU_4"));
    HStrList.push_back(QString("GPU_5"));
    HStrList.push_back(QString("GPU_6"));
    HStrList.push_back(QString("GPU_7"));
    HStrList.push_back(QString("GPU_8"));
    HStrList.push_back(QString("GPU_9"));
    HStrList.push_back(QString("GPU_10"));
    HStrList.push_back(QString("GPU_11"));
    HStrList.push_back(QString("GPU_12"));
    HStrList.push_back(QString("GPU_13"));
    HStrList.push_back(QString("GPU_14"));
    HStrList.push_back(QString("GPU_15"));
    HStrList.push_back(QString("Average_Value"));
    HStrList.push_back(QString("Total_Values"));
 
    //设置行列数(只有列存在的前提下,才可以设置列标签)
    int HlableCnt=HStrList.count();
    ui->m_CounttableWidget->setRowCount(3);//设置3行
    ui->m_CounttableWidget->setColumnCount(HlableCnt);//设置读取的HStrList关键字列数
 
    //设置列标签
    ui->m_CounttableWidget->setHorizontalHeaderLabels(HStrList);
 
    //设置行标签
    QStringList rowLabls;
    rowLabls.push_back(QString::fromLocal8Bit("算率.Mh/s"));
    rowLabls.push_back(QString::fromLocal8Bit("温度.C"));
    rowLabls.push_back(QString::fromLocal8Bit("测试结果"));
    ui->m_CounttableWidget->setVerticalHeaderLabels(rowLabls);
 
    //设置每一列的宽度
    for(int l=0;l<HStrList.count()-2;l++)
        ui->m_CounttableWidget->setColumnWidth(l,55);
    ui->m_CounttableWidget->setColumnWidth(HStrList.count()-2,102);
    ui->m_CounttableWidget->setColumnWidth(HStrList.count()-1,102);
 
 
    //设置每一行的高度
    for(int r=0;r<ui->m_CounttableWidget->rowCount();r++)
        ui->m_CounttableWidget->setRowHeight(r,55);
    ui->m_CounttableWidget->horizontalHeader()->setFixedHeight(80);//设置表头高度
    //ui->m_CounttableWidget->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);//去掉水平滚动条
    //ui->m_CounttableWidget->item(0,0)->setTextAlignment(Qt::AlignHCenter);//单元格字体对齐
    //ui->m_CounttableWidget->item(1,0)->setBackground(QColor(0,60,10));//设置字体背景颜色
    //ui->m_CounttableWidget->item(1,0)->setTextColor(QColor(200,111,100));//设置字体颜色
    //ui->m_CounttableWidget->item(1,0)->setFont(QFont("Helvetica"));//设置字体
    ui->m_CounttableWidget->setShowGrid(true);//显示表格线
 
    //设置表头不可点击
    ui->m_CounttableWidget->horizontalHeader()->setStyleSheet("QHeaderView::section{background-color: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 rgba(134, 245, 99, 255),stop:0.5 rgba(134, 148, 99, 255),stop:1 rgba(115, 87, 128, 255));color:rgb(25, 70, 100);padding-left: 1px;border: 1px solid #FFFF00;}"); //设置表头背景色
    ui->m_CounttableWidget->setAlternatingRowColors(true);
}
 
void ETH_TEST::timernumber()//定时执行
{
    if((this->secondnumber)>1)
    {
        this->EveryprogressValues=100/QString(this->ConfiArgc[0]).toDouble();
        QString Temp=QString::number(this->secondnumber)+"S";
        ui->label_2->setText(Temp);
        ui->progressBar->setValue((this->SetprogressTotalValues)-(this->progressTotalValues));//当前进度条值
        this->progressTotalValues+=this->EveryprogressValues;//进度条总增长值
        this->secondnumber--;//执行秒数倒计时
    }
    else
    {
        ui->progressBar->setValue(0);
        ui->label_2->setText(QString::fromUtf8("定时测试完成!!"));
        if(process)//关闭进程
        {
            process->close();
            //delete process;
            //process=0;
        }
        this->secondnumber=0;
        this->IsNotTime=true;
        m_timer->stop();
    }
}
 
void ETH_TEST::StartQProgressBarSlot(int runtimer)//设置及执行进度条
{
    this->secondnumber=runtimer;
    QFont ft;
    ft.setPointSize(11);
    ui->progressBar->setFont(ft);//设置进度条字体大小
    ui->label_2->setFont(ft);//设置计时器字体大小
    ui->progressBar->setMinimum(0);//进度条最小值
    ui->progressBar->setMaximum(100);//进度条最大值
    ui->progressBar->setValue(100);//当前进度条
    ui->progressBar->setOrientation(Qt::Horizontal);//水平方向
    //ui->progressBar->setInvertedAppearance(true);//反方向
    //this->EveryprogressValues=1;//绑定进度条执行尺度
    this->SetprogressTotalValues=100;//进度条最大值
    ui->progressBar->setStyleSheet("QProgressBar::chunk{background-color:rgb(153,188,0)}");//设置进度条颜色
    QObject::connect(m_timer,SIGNAL(timeout()),this,SLOT(timernumber()));//启动计时
    m_timer->start(1000);
}
 
void ETH_TEST::closeEvent(QCloseEvent *event)
{
    process->kill();
    if(!process->waitForFinished(100))
        return;
    event->accept();
}
 
void ETH_TEST::finish_process(int exitCode, QProcess::ExitStatus exitStatus)
{
    if(exitStatus==QProcess::NormalExit)
    {
        ui->cmdEdit->append("process exit normal");
    }
    else
    {
        ui->cmdEdit->append("process exit crash");
    }
    ui->cmdEdit->append("process finised");
}
 
void ETH_TEST::start_read_output()
{
    QByteArray ba=process->readAllStandardOutput();
    ui->cmdEdit->append(QString::fromLocal8Bit(ba));
}
 
void ETH_TEST::start_read_err_output()
{
    QByteArray ba=process->readAllStandardError();
    ui->cmdEdit->append(QString::fromLocal8Bit(ba));
}
 
void ETH_TEST::StartSupportForChinese()
{
    //启动QT对中文支持
    QTextCodec *codec=QTextCodec::codecForName("GB2312");
    QTextCodec::setCodecForLocale(codec);
    QObject::connect(process,SIGNAL(readyReadStandardOutput()),this,SLOT(start_read_output()));
    QObject::connect(process,SIGNAL(readyReadStandardError()),this,SLOT(start_read_err_output()));
    QObject::connect(process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(finish_process(int,QProcess::ExitStatus)));
}
 
//调用脚本并并生成LOG FILE 到TEXTEDIT
bool ETH_TEST::CallAnExternalProgram(QString exe)
{
    process->start(exe);
    if(false==process->waitForStarted())
    {
        //ui->cmdEdit->append("Process call fail!");
        QMessageBox::information(this,"System Err",QString::fromLocal8Bit("执行文件报错!!"));
        QFile file("fail.txt");
        file.open(QFile::WriteOnly|QFile::Text);
        file.close();
        return false;
    }
    else
    {
        //ui->cmdEdit->append("Process all successed!!");
        return true;
    }
 
}
 
//读取cmdEdit字符串分析处理存储于CalcalateRateValue及TemperatureValue储存于QStringList中
void ETH_TEST::ProcessSortStrSlot()
{
    QStringList list=ui->cmdEdit->toPlainText().split("\n");//以回车为截点按行存储
    QStringList CountreplaceStrSample;//数率截取替换的字符串组
    CountreplaceStrSample<<" Mh/s"<<"GPU0 "<<"GPU1 "<<"GPU2 "<<"GPU3 "<<"GPU4 "<<"GPU5 "<<"GPU6 "<<"GPU7 "<<"GPU8 "<<"GPU9 "<<"GPU10 "<<"GPU11 "<<"GPU12 "<<"GPU13 ";
    QStringList TempreplaceStrSample;//温度截取替换的字符串组
    TempreplaceStrSample<<"GPU0 t="<<"GPU1 t="<<"GPU2 t="<<"GPU3 t="<<"GPU4 t="<<"GPU5 t="<<"GPU6 t="<<"GPU7 t="<<"GPU8 t="<<"GPU9 t="<<"GPU10 t="<<"GPU11 t="<<"GPU12 t="<<"GPU13 t=";
    int n=0,t=0;
    foreach (QString Temp, list)
    {
        if(Temp.length()>30)//过滤字符串长度小于30的数据
        {
            QStringList CountStr=Temp.split("ETH: GPU0 ");//读取CMDEDITSHOW算率字符串
            if(CountStr.size()>=2)//判断是否符合取的数据且数据不是已读取过的数据
            {
                if(n>=this->Callen+QString(this->ConfiArgc[3]).toInt())
                {
                    QStringList StrInitProcess1=QString(CountStr[1]).split(", ");//以“, ”为分隔点分离字符串存储于字符串数组中
                    QString StrInitProcess2;
                    double totalvalue=0.0;
                    foreach (QString rpstr1, StrInitProcess1)//循环读取字符串数组
                    {
                        QString Tempe;
                        Tempe=rpstr1;
                        foreach (QString rpstr2, CountreplaceStrSample)//循环读取替换字符串标准值
                        {
                            if(Tempe.contains(rpstr2),Qt::CaseSensitive)//判断是否存在
                            {
                                Tempe.replace(QRegExp(rpstr2),"");//替换字符串中多余的字符串
                            }
                        }
                        totalvalue+=Tempe.toDouble();//将字符串转换为双精度并执行叠加运算
                        StrInitProcess2+=Tempe+",";//将字符串增加分号隔离
                    }
                    if((StrInitProcess1.size())<(QString(this->ConfiArgc[2]).toInt()))//如果测试卡数少读取的卡数执行设置0值
                    {
                        //for(int el=(StrInitProcess1.size()-1);el<=(QString(this->ConfiArgc[2]).toInt());el++)
                        for(int n=0;n<(QString(this->ConfiArgc[2]).toInt())-(StrInitProcess1.size());n++)
                        {
                            StrInitProcess2+="0,";//读取数据量不常符合标准时少于的量赋值0
                        }
                    }
                    StrInitProcess2+=QString::number(totalvalue/(QString(this->ConfiArgc[2]).toInt()))+",";//添加算率平均值
                    StrInitProcess2+=QString::number(totalvalue);//将数字转换为字符串并组合
 
 
                    this->FillTableData(StrInitProcess2,1);//将算率数据插入数格
 
                    this->Calcalate_rate_Value.append(StrInitProcess2);//将数据存储
                    this->Callen++;
                }
                n++;
            }
            QStringList TemperStr=Temp.split("GPU0 t=");//读取温度字符串
            if(TemperStr.size()>=2)//读取CMDEDITSHOW温度字符串
            {
                if((t-(this->ConfiArgc[3].toInt()-3))>=this->Temlen)
                {
                    QStringList StrInitProcess1=QString(TemperStr[1]).split(", ");//以“, ”为分隔点分离字符串存储于字符串数组中
                    QString StrInitProcess2;
                    int totalTemplater=0;
                    foreach (QString rpstr1, StrInitProcess1)//循环读取字符串数组
                    {
                        //QStringList MoveStr=rpstr1.split(" ");
                        QString Tempe;
                        Tempe=rpstr1;
                        foreach (QString rpstr2, TempreplaceStrSample)//循环读取替换字符串标准值
                        {
                            if(Tempe.contains(rpstr2),Qt::CaseSensitive)//判断是否存在
                            {
                                Tempe.replace(QRegExp(rpstr2),"");//替换字符串中多余的字符串
                            }
                        }
                        QStringList MoveStr=Tempe.split("C ");//分隔"C "两端了符串
                        Tempe=MoveStr[0];
                        totalTemplater+=Tempe.toInt();//将字符串转换为整型并执行叠加运算
                        StrInitProcess2+=Tempe+",";//将字符串增加分号隔离
                    }
                    if((StrInitProcess1.size())<(QString(this->ConfiArgc[2]).toInt()))//如果测试卡数少读取的卡数执行设置0值
                    {
                        //for(int el=(StrInitProcess1.size()-1);el<=(QString(this->ConfiArgc[2]).toInt());el++)
                        for(int n=0;n<(QString(this->ConfiArgc[2]).toInt())-(StrInitProcess1.size());n++)
                        {
                            StrInitProcess2+="0,";//读取数据量不常符合标准时少于的量赋值0
                        }
                    }
                    StrInitProcess2+=QString::number(totalTemplater/(QString(this->ConfiArgc[2]).toInt()))+",";//添加温度平均值
                    StrInitProcess2+=QString::number(totalTemplater);//将数字转换为字符串并组合
                    FillTableData(StrInitProcess2,2);//将温控数据插入数格
                    this->Temperature_Value.append(StrInitProcess2);//将数据存储
                    this->Temlen++;
                }
 
                t++;
            }
        }
    }
}
 
//将数据填充到表格中
void ETH_TEST::FillTableData(QString str,int Item)
{
      QStringList MoveStrData=str.split(",");//将字符串数据以“,”分离形式存储
      int TableColumnCount=ui->m_CounttableWidget->columnCount();//获取表格列数
      if(Item==1)//表格第一列内容填入
      {
           for(int l=0;l<MoveStrData.size()-2;l++)
            {
                double value1=QString(MoveStrData[l]).toDouble();
                double value2=QString(this->ConfiArgc[4]).toDouble();
 
                //插入数据
                ui->m_CounttableWidget->setItem(0,l,new QTableWidgetItem(MoveStrData[l]));
                if(value1>=value2)
                {
                    ui->m_CounttableWidget->item(0, l)->setForeground(QBrush(QColor(0, 85, 0)));//设置绿色字体
                    ui->m_CounttableWidget->setItem(2,l,new QTableWidgetItem("PASS"));
                    ui->m_CounttableWidget->item(2, l)->setForeground(QBrush(QColor(0, 85, 0)));//设置绿色字体
                }
                else
                {
                    ui->m_CounttableWidget->item(0, l)->setForeground(QBrush(QColor(255, 0, 0)));//设置红色字体
                    ui->m_CounttableWidget->setItem(2,l,new QTableWidgetItem("FAIL"));
                    ui->m_CounttableWidget->item(2, l)->setForeground(QBrush(QColor(255, 0, 0)));//设置红色字体
                    this->IsAllStatePas=false;
                }
            }
 
            //平均算率
            //插入数据
            ui->m_CounttableWidget->setItem(0,TableColumnCount-2,new QTableWidgetItem(MoveStrData[MoveStrData.size()-2]+"Ms/h"));
            if((QString(MoveStrData[MoveStrData.size()-2]).toDouble())>=(QString(this->ConfiArgc[4]).toDouble()))
            {
                ui->m_CounttableWidget->item(0,TableColumnCount-2)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-2,new QTableWidgetItem("PASS"));
                ui->m_CounttableWidget->item(2,TableColumnCount-2)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
            }
            else
            {
                ui->m_CounttableWidget->item(0,TableColumnCount-2)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-2,new QTableWidgetItem("FAIL"));
                ui->m_CounttableWidget->item(2,TableColumnCount-2)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                this->IsAllStatePas=false;
            }
 
            //总算率
            //插入数据
            ui->m_CounttableWidget->setItem(0,TableColumnCount-1,new QTableWidgetItem(MoveStrData[MoveStrData.size()-1]+"Ms/h"));
            if((QString(MoveStrData[MoveStrData.size()-1]).toDouble())>=(QString(this->ConfiArgc[4]).toInt()*QString(this->ConfiArgc[2]).toInt()))
            {
                ui->m_CounttableWidget->item(0,TableColumnCount-1)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-1,new QTableWidgetItem("PASS"));
                ui->m_CounttableWidget->item(2,TableColumnCount-1)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
            }
            else
            {
                ui->m_CounttableWidget->item(0,TableColumnCount-1)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-1,new QTableWidgetItem("FAIL"));
                ui->m_CounttableWidget->item(2,TableColumnCount-1)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                this->IsAllStatePas=false;
            }
      }
      else if(Item==2)//表格第二列内容填入
      {
            for(int l=0;l<MoveStrData.size()-2;l++)
            {
                double value1=QString(MoveStrData[l]).toDouble();
                double value2=QString(this->ConfiArgc[5]).toDouble();
                //插入数据
                ui->m_CounttableWidget->setItem(1,l,new QTableWidgetItem(MoveStrData[l]));
                if(value1<=value2&&value1>0)
                {
                   ui->m_CounttableWidget->item(1,l)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                   ui->m_CounttableWidget->setItem(2,l,new QTableWidgetItem("PASS"));
                   ui->m_CounttableWidget->item(2,l)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                }
                else
                {
                    ui->m_CounttableWidget->item(1,l)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                    ui->m_CounttableWidget->setItem(2,l,new QTableWidgetItem("FAIL"));
                    ui->m_CounttableWidget->item(2,l)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                    this->IsAllStatePas=false;
                }
            }
 
            //平均算率
            //插入数据
            ui->m_CounttableWidget->setItem(1,TableColumnCount-2,new QTableWidgetItem(MoveStrData[MoveStrData.size()-2]+"C"));
            if((QString(MoveStrData[MoveStrData.size()-2]).toInt())<=(QString(this->ConfiArgc[5]).toInt()))
            {
                ui->m_CounttableWidget->item(1,TableColumnCount-2)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-2,new QTableWidgetItem("PASS"));
                ui->m_CounttableWidget->item(2,TableColumnCount-2)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
            }
            else
            {
                ui->m_CounttableWidget->item(1,TableColumnCount-2)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-2,new QTableWidgetItem("FAIL"));
                ui->m_CounttableWidget->item(2,TableColumnCount-2)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                this->IsAllStatePas=false;
            }
 
            //总算率
            //插入数据
            ui->m_CounttableWidget->setItem(1,TableColumnCount-1,new QTableWidgetItem(MoveStrData[MoveStrData.size()-1]+"C"));
            if((QString(MoveStrData[MoveStrData.size()-1]).toDouble())<=(QString(this->ConfiArgc[5]).toInt()*QString(this->ConfiArgc[2]).toInt()))
            {
                ui->m_CounttableWidget->item(1,TableColumnCount-1)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-1,new QTableWidgetItem("PASS"));
                ui->m_CounttableWidget->item(2,TableColumnCount-1)->setForeground(QBrush(QColor(0,85,0)));//设置绿色字体
            }
            else
            {
                ui->m_CounttableWidget->item(1,TableColumnCount-1)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                ui->m_CounttableWidget->setItem(2,TableColumnCount-1,new QTableWidgetItem("FAIL"));
                ui->m_CounttableWidget->item(2,TableColumnCount-1)->setForeground(QBrush(QColor(255,0,0)));//设置红色字体
                this->IsAllStatePas=false;
            }
      }
}
 

MAIN.CPP SOURCE CODE:

#include "eth_test.h"
#include <QApplication>
#include <QDir>
#include <QIcon>
#include <QTextCodec>
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    ETH_TEST w;
    w.setMaximumSize(1196,870);
    w.setMinimumSize(1196,870);
 
    QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));
    QTextCodec::setCodecForLocale(QTextCodec::codecForName("GBK"));
    QTextCodec::setCodecForCStrings(QTextCodec::codecForName("GB2312"));
    a.setWindowIcon(QIcon("main.icos"));
    w.show();
 
    return a.exec();
}
 




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值