Qt完整项目--工控系统(可直接运行)

1、首先肯定是需要登录注册的。
因为这个项目是没有连接数据库的。Username和Password都是存取在本地的txt文档中,不需要自己另外创建,运行注册的时候会代码创建txt文档。系统里面的内容也如同。
注意:我们这边需要用QtCharts,这个需要Qt5.7版本以上安装的时候把那个QChart选项勾选上才能使用这个模块。有问题可以来私。
Qt完整项目--工控系统(可直接运行)_第1张图片
2、登录进去后根据数据生成柱状图。
Qt完整项目--工控系统(可直接运行)_第2张图片
柱状图cpp

#include "maininterface.h"
#include "ui_maininterface.h"
#include
#include"quanjvbianliang.h"
MainInterface::MainInterface(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainInterface)
{
    ui->setupUi(this);

    //bargrap = new bargraph(this);
    //bargrap->resize(400,300);
    //ui->stackedWidget->addWidget(bargrap);
    //ui->stackedWidget->setCurrentWidget(bargrap);
    QBarSet *set0 = new QBarSet("日光(分钟)");
    QBarSet *set1 = new QBarSet("紫外(分钟)");
    QBarSet *set2 = new QBarSet("日光(小时)");
    QBarSet *set3 = new QBarSet("紫外(小时)");

    //*set0 <getIDRGFZ().toInt();
    //*set1 <getIDRGXH().toInt();
    //*set2 <getIDZYFZ().toInt();
    //*set3 <getIDZYXH().toInt();

    /*set0 << 1 << 2 << 3 << 4 << 5 << 6;
    *set1 << 5 << 0 << 0 << 4 << 0 << 7;
    *set2 << 3 << 5 << 8 << 13 << 8 << 5;
    *set3 << 5 << 6 << 7 << 3 << 4 << 5;*/

//![1]

//![2]
    QBarSeries *series = new QBarSeries();
    series->append(set0);
    series->append(set1);
    series->append(set2);
    series->append(set3);


//![2]

//![3]
    QChart *chart = new QChart();//构建一个QChart对象
    chart->addSeries(series);
    chart->setTitle("光照统计");
    chart->setAnimationOptions(QChart::SeriesAnimations);
//![3]

//![4]
    QStringList categories;
    categories << "Jan" << "Feb" << "Mar" << "Apr" << "May" << "Jun";
    QBarCategoryAxis *axisX = new QBarCategoryAxis();
    axisX->append(categories);
    chart->addAxis(axisX, Qt::AlignBottom);
    series->attachAxis(axisX);

    QValueAxis *axisY = new QValueAxis();
    axisY->setRange(0,13);
    chart->addAxis(axisY, Qt::AlignLeft);
    series->attachAxis(axisY);
//![4]

//![5]
    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);
//![5]

//![6]
//!
    chart->resize(this->height(),this->height());
    chartView = new QChartView(chart,this);
    chartView->setRenderHint(QPainter::Antialiasing);
    chartView->move(200,40);
    chartView->resize(760,410);

    connect(ui->lineEditRGFZ,&QLineEdit::editingFinished,[=](){
        *set0<<ui->lineEditRGFZ->text().toUtf8().toInt();
        ui->lineEditRGFZ->clear();
    });
    connect(ui->lineEditRGXH,&QLineEdit::editingFinished,[=](){
        *set1<<ui->lineEditRGXH->text().toUtf8().toInt();
        ui->lineEditRGXH->clear();
    });
    connect(ui->lineEditZGFZ,&QLineEdit::editingFinished,[=](){
        *set2<<ui->lineEditZGFZ->text().toUtf8().toInt();
        ui->lineEditZGFZ->clear();
    });
    connect(ui->lineEditZGXH,&QLineEdit::editingFinished,[=](){
        *set3<<ui->lineEditZGXH->text().toUtf8().toInt();
        ui->lineEditZGXH->clear();
    });
}

MainInterface::~MainInterface()
{
    delete ui;
}



3、操作记录
Qt完整项目--工控系统(可直接运行)_第3张图片

#include "caozuojl.h"
#include "ui_caozuojl.h"
#include
#include"quanjvbianliang.h"
#include
#include
#include
#include
caozuojl::caozuojl(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::caozuojl)
{
    ui->setupUi(this);
    connect(ui->pushButton,&QPushButton::clicked,[=](){
        QFile file("D:/mylog.txt");
        if (!file.open(QIODevice::ReadOnly	 | QIODevice::Text))
        {
            qDebug()<<"log读取失败";
            return;
        }
        //构建QTextStream读取文本
        QTextStream in(&file);
        //将应用程序的光标设置为等待状态
        QApplication::setOverrideCursor(Qt::WaitCursor);
        //转码
        in.setCodec("UTF-8");
        //显示到textEdit文本框
        ui->tableWidget->setRowCount(200);
        ui->tableWidget->setColumnCount(2);
        ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"事件"<<"时间");
        ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
        ui->tableWidget->horizontalHeader()->setStretchLastSection(true);

        QStringList list = in.readAll().split("\n",QString::SkipEmptyParts);
        //list = in.readAll().split("-----",QString::SkipEmptyParts);
        int num = 0;
        for(int i = 0;i<list.length();i+=2)
        {

            ui->tableWidget->setItem(num,0,new QTableWidgetItem(list[i]));
            ui->tableWidget->setItem(num,1,new QTableWidgetItem(list[i+1]));
            num++;
            //QString lan = QTableWidgetItem(list[i]);
        }
        //ui->textEdit->setPlainText(in.readAll());
        //读取完成后恢复光标状态
        QApplication::restoreOverrideCursor();
    });
}

caozuojl::~caozuojl()
{
    delete ui;
}

void caozuojl::on_pushButton_clicked()
{

}

4、串口调试。Qt完整项目--工控系统(可直接运行)_第4张图片
其他的都是一些较为简单的一些业务操作,可以自己进去玩玩看。
下载地址:https://download.csdn.net/download/weixin_48268336/21775223

你可能感兴趣的:(Qt,C/C++,qt,c++)