目錄
一 軟件原型效果
二 功能列表
三 代碼實(shí)現(xiàn)
四 測(cè)試驗(yàn)證
五 項(xiàng)目工程打包發(fā)布
六 項(xiàng)目完整源碼獲取
一 軟件原型效果
登錄頁(yè)面效果:
?主頁(yè)實(shí)現(xiàn)效果:點(diǎn)擊左邊的菜單欄可以切換右邊的頁(yè)面,實(shí)現(xiàn)多功能輪流顯示效果。
二 功能列表
- 有一個(gè)用戶(hù)名輸入框,可以輸入任意字符;
- 有一個(gè)密碼輸入框,可以輸入任意字符,但是需要以 *代替文本顯示,避免密碼泄露;
- 有一個(gè)登錄按鈕,當(dāng)點(diǎn)擊登錄按鈕時(shí),到數(shù)據(jù)庫(kù)檢驗(yàn)用戶(hù)名與密碼的正確性,如果用戶(hù)名密碼驗(yàn)證正確,則跳轉(zhuǎn)到程序主操作頁(yè)面,否則提示用戶(hù)檢驗(yàn)用戶(hù)名或密碼是否正確。
- 海康攝像頭視頻預(yù)覽、下載功能;
- 日志解析功能;
- 設(shè)備感應(yīng)器信號(hào)實(shí)時(shí)查看功能;
- 發(fā)送指令操作設(shè)備硬件的功能;
三 代碼實(shí)現(xiàn)
代碼總共有七個(gè)類(lèi),功能分別如下:
類(lèi)名稱(chēng) | 類(lèi)含義 |
---|---|
main.cpp |
程序入口類(lèi),一般創(chuàng)建工程時(shí)自動(dòng)創(chuàng)建,暫未做相關(guān)代碼修改; |
mainwindow.cpp mainwindow.h |
登錄頁(yè)面類(lèi),主要實(shí)現(xiàn)軟件的登錄功能,包括用戶(hù)名、密碼的校驗(yàn); |
databaseclass.h databaseclass.cpp | 數(shù)據(jù)庫(kù)操作類(lèi),此項(xiàng)目使用的是的Qt自帶sqlite嵌入式數(shù)據(jù)庫(kù); |
controller.h controller.cpp |
程序主控制類(lèi),控制功能頁(yè)面的跳轉(zhuǎn)、增加、刪除; |
hk_widget.h hk_widget.cpp |
監(jiān)控視頻功能頁(yè)面,可按實(shí)際需求進(jìn)行修改與完善; |
loganalysisclass.h loganalysisclass.cpp | 日志分析功能頁(yè)面,可按實(shí)際需求進(jìn)行修改與完善; |
iodisplayclass.h iodisplayclass.cpp | IO監(jiān)視功能頁(yè)面,可按實(shí)際需求進(jìn)行修改與完善; |
hardwareoperationclass.h hardwareoperationclass.cpp | 硬件操作功能頁(yè)面,可按實(shí)際需求進(jìn)行修改與完善; |
res.qrc | 資源管理文件,包括圖片、圖標(biāo)資源; |
源代碼列表:
main.cpp
#include "controller.h"
#include "hk_widget.h"
#include "mainwindow.h"
#include <QApplication>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
// controller ct;
// ct.show();
// HK_Widget hk;
// hk.show();
return a.exec();
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "QtSql/qsqldatabase.h"
#include <QMainWindow>
#include<QSharedPointer>
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
#include<QtSql/QSqlError>
#include<QVector>
#include<QDebug>
#include <QLineEdit>
#include <QPushButton>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = nullptr);
~MainWindow();
void initDataBase();
// QWidget interface
protected:
void paintEvent(QPaintEvent *event);
private slots:
void loginSucessSlot(); //登錄按鈕的響應(yīng)邏輯槽函數(shù)
void regSlot(); //注冊(cè)賬戶(hù)按鈕
private:
QSqlDatabase db;
QSqlQuery *sq;
QLineEdit *nm;
QLineEdit *ps;
QPushButton *login;
QPushButton *reg;
};
#endif // MAINWINDOW_H
mainwindow.cpp
#include "controller.h"
#include "mainwindow.h"
#include<QFormLayout>
#include <QGuiApplication>
#include <QLabel>
#include<QLineEdit>
#include <QPainter>
#include <QPalette>
#include <QPixmap>
#include <QPoint>
#include<QPushButton>
#include <QRect>
#include<QScreen> //獲取當(dāng)前電腦的屏幕尺寸
#include<QMessageBox>
#include<QInputDialog>
#include <QIcon>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
QScreen *sreen=QGuiApplication::primaryScreen(); //獲取主屏幕對(duì)象
QRect rect=sreen->availableGeometry(); //獲取屏幕的可用大小
// const int WIDTH=rect.size().width(); //屏幕的寬
// const int HEIGHT=rect.size().height(); //獲取屏幕的高
// const int X=rect.x();
// const int Y=rect.y();
//設(shè)置窗體的一些屬性
resize(600,600);
setWindowTitle("設(shè)備醫(yī)生-登錄頁(yè)面");
setWindowIcon(QIcon(":/login.png"));
setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint); //禁用窗體的最大化按鈕
setFixedSize(width(),height()); //直接設(shè)置大小,禁用鼠標(biāo)拖放改變窗體的大小
//qDebug()<<X<<Y<<WIDTH<<HEIGHT<<this->x()<<this->y();
//把當(dāng)前窗體移動(dòng)到屏幕中央
rect=this->frameGeometry();
QPoint centerPoint=sreen->availableGeometry().center();
rect.moveCenter(centerPoint);
this->move(rect.topLeft());
//設(shè)置背景圖片
//setStyleSheet("MainWindow{ background-image: url(:/back2.jpg);}");
//創(chuàng)建widget對(duì)象
QWidget *w=new QWidget;
w->setContentsMargins(width()/4,width()/4,width()/4,width()/4);
QFormLayout *fm=new QFormLayout;
fm->setSpacing(50); //設(shè)置中間的間隔
fm->setHorizontalSpacing(5); //設(shè)置水平方向兩個(gè)控件之間的位置
//用戶(hù)名
QLabel *name=new QLabel("用戶(hù)名: ");
nm=new QLineEdit;
//密碼
QLabel *password=new QLabel("密 碼:");
ps=new QLineEdit;
ps->setEchoMode(QLineEdit::Password); //輸入密碼時(shí)設(shè)置為密碼模式
//登錄按鈕
login=new QPushButton("登 錄");
//注冊(cè)按鈕
reg=new QPushButton("注 冊(cè)");
//定義控件的背景色和漸變色
QString styleColor= "background-color: rgb(0, 170, 0);"
"background-color: qconicalgradient(cx:0, cy:0, angle:135, "
"stop:0 rgba(255, 255, 0, 69), stop:0.375 rgba(255, 255, 0, 69), "
"stop:0.423533 rgba(251, 255, 0, 145), stop:0.45 rgba(247, 255, 0, 208), "
"stop:0.477581 rgba(255, 244, 71, 130), stop:0.518717 rgba(255, 218, 71, 130), "
"stop:0.55 rgba(255, 255, 0, 255), stop:0.57754 rgba(255, 203, 0, 130), "
"stop:0.625 rgba(255, 255, 0, 69), stop:1 rgba(255, 255, 0, 69));";
//給控件設(shè)置背景顏色和漸變色
login->setStyleSheet(styleColor);
name->setStyleSheet(styleColor);
password->setStyleSheet(styleColor);
reg->setStyleSheet(styleColor);
fm->addRow(name,nm);
fm->addRow(password,ps);
fm->addRow(login);
fm->addRow(reg);
w->setLayout(fm);
setCentralWidget(w);
//綁定按鈕的信號(hào)與槽
connect(login,SIGNAL(clicked(bool)),this,SLOT(loginSucessSlot()));
connect(reg,SIGNAL(clicked(bool)),this,SLOT(regSlot()));
initDataBase();//初始化數(shù)據(jù)庫(kù)的連接與打開(kāi)
}
MainWindow::~MainWindow()
{
//使用結(jié)束時(shí)關(guān)閉數(shù)據(jù)庫(kù),回收內(nèi)存
db.close();
delete sq;
delete nm;
delete ps;
delete login;
delete reg;
qDebug()<<"登錄窗口退出并已經(jīng)銷(xiāo)毀";
}
//初始化數(shù)據(jù)庫(kù)的連接與打開(kāi)
void MainWindow::initDataBase()
{
sq=NULL;
//連接數(shù)據(jù)庫(kù)
if (QSqlDatabase::contains("qt_sql_default_connection"))
{
db = QSqlDatabase::database("qt_sql_default_connection");
}
else
{
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("mydb.db");
db.setUserName("root");
db.setPassword("123456");
}
if(db.open()){
qDebug()<<"連接SQLite成功: ";
//當(dāng)只有一個(gè)數(shù)據(jù)庫(kù)時(shí),我們需要把sqlQuery類(lèi)與數(shù)據(jù)庫(kù)進(jìn)行綁定,不然會(huì)執(zhí)行語(yǔ)句失敗和導(dǎo)入驅(qū)動(dòng)失敗
sq=new QSqlQuery("mydb.db");
QString create_sql = "create table student (name varchar(30) UNIQUE, password varchar(30));";
if(sq->exec(create_sql))
qDebug()<< "創(chuàng)建表成功:";
else
qDebug()<< "表創(chuàng)建失?。?+sq->lastError().text();
}else{
qDebug()<< "連接SQLite失敗: "<<db.lastError().text();
}
}
//重寫(xiě)繪制函數(shù),在里面設(shè)置背景圖片
void MainWindow::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)
QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawPixmap(rect(),QPixmap(":/back2.jpg"));
}
//登錄成功按鈕的響應(yīng)邏輯槽函數(shù)
void MainWindow::loginSucessSlot()
{
//獲取輸入的用戶(hù)名與密碼
QString name=nm->text().trimmed();
QString password=ps->text().trimmed();
// //如果用戶(hù)名和密碼為空,彈出提示信息,禁用登錄按鈕
if(name.isEmpty() || password.isEmpty()){
QMessageBox::information(this,"登錄結(jié)果提示框","用戶(hù)名、密碼不能為空!",QMessageBox::Ok);
qDebug()<<"用戶(hù)名、密碼不能為空!";
}else {
QString nm,pw;
// //在數(shù)據(jù)庫(kù)中查詢(xún)用戶(hù)信息
QString sql=QString("select *from student where name='%1';").arg(name);
// //開(kāi)始執(zhí)行查詢(xún)語(yǔ)句
if(sq->exec(sql)){
while (sq->next()) {
nm=sq->value("name").toString();
pw=sq->value("password").toString();
}
qDebug()<<"查詢(xún)成功";
if(name==nm && password==pw){
//密碼比對(duì)正確,登錄成功!
//QMessageBox::information(this,"登錄結(jié)果提示框","恭喜你,登錄成功!",QMessageBox::Ok);
//建立新窗口對(duì)象并顯示,提示隱藏登錄窗口
this->hide();
controller *c=new controller();
c->show();
this->close();
}else {
QMessageBox::information(this,"登錄結(jié)果提示框","密碼錯(cuò)誤,登錄失?。?,QMessageBox::Ok);
}
}else{
qDebug()<<"查詢(xún)數(shù)據(jù)失敗:";
}
}
}
//注冊(cè)賬戶(hù)
void MainWindow::regSlot()
{
QString name,password;
bool flag;
QInputDialog dialog;
QString np=dialog.getMultiLineText(this,"賬戶(hù)注冊(cè)","用戶(hù)名與密碼之間用一個(gè)空格隔開(kāi)","",&flag);
if(flag){
if(! (np.trimmed().isEmpty()) ){
QStringList list=np.split(" ");
if(list.length()==2){
name=list.at(0).trimmed();
qDebug()<<name;
password=list.at(1).trimmed();
qDebug()<<password;
//插入一條數(shù)據(jù)
QString sql=QString( "insert into student(name,password) values('%1',%2);").arg(name).arg(password);
if(sq->exec(sql)){
qDebug()<<"插入成功";
QMessageBox::information(this,"注冊(cè)結(jié)果提示框","注冊(cè)成功,請(qǐng)使用剛剛注冊(cè)成功的賬號(hào)與密碼登錄!",QMessageBox::Ok);
}else{
QMessageBox::information(this,"注冊(cè)結(jié)果提示框","注冊(cè)失敗,請(qǐng)?jiān)囋嚨卿浕蛑匦伦?cè)新賬戶(hù)",QMessageBox::Ok);
qDebug()<<"插入失敗";
}
}
}
}
}
databaseclass.h
#ifndef DATABASECLASS_H
#define DATABASECLASS_H
#include <QObject>
#include<QtSql/QSqlDatabase>
#include<QtSql/QSqlQuery>
#include<QtSql/QSqlError>
#include<QVector>
#include<QMutex>
#include<QSharedPointer>
#include<QDebug>
#include<stdio.h>
/*
數(shù)據(jù)庫(kù)操作類(lèi)設(shè)計(jì)要點(diǎn):
1,把數(shù)據(jù)庫(kù)設(shè)計(jì)為單例模式,確保整個(gè)程序只有一個(gè)數(shù)據(jù)實(shí)例;
2,使用鎖機(jī)制確保多線(xiàn)程操作時(shí)安全訪問(wèn);
3,使用智能指針管理全局對(duì)象,在適當(dāng)?shù)臅r(shí)機(jī)自動(dòng)釋放對(duì)象。
*/
class DatabaseClass:public QObject
{
Q_OBJECT
public:
DatabaseClass();
~DatabaseClass();
//數(shù)據(jù)庫(kù)的連接、增、刪、改、查、數(shù)據(jù)庫(kù)關(guān)閉的方法
//建立并連接數(shù)據(jù)庫(kù),并提供數(shù)據(jù)庫(kù)的連接名稱(chēng)、數(shù)據(jù)庫(kù)的驅(qū)動(dòng)名稱(chēng)、需要新建的數(shù)據(jù)庫(kù)名稱(chēng)、訪問(wèn)數(shù)據(jù)庫(kù)的用戶(hù)名、訪問(wèn)數(shù)據(jù)庫(kù)的密碼
bool databaseCreate(QString sqlConnectName="qt_sql_default_connection",QString databaseDriverName="QSQLITE",QString databaseName="my_db.db",QString userName="root",QString password="123456");
//建立數(shù)據(jù)庫(kù)表
bool createTable(QString createTableSql);
//查詢(xún)數(shù)據(jù): 把查詢(xún)到的數(shù)據(jù)存放在集合中
QVector<QString> selectData(QString SelectSql);
//增加數(shù)據(jù)
bool insertData(QString insertSql);
//修改數(shù)據(jù)
bool updateData(QString updateSql);
//刪除數(shù)據(jù)
bool deleteData(QString deleteData);
private:
QVector<QString> vector;
//數(shù)據(jù)庫(kù)操作對(duì)象
QSqlDatabase db;
QSharedPointer<QSqlQuery> sq=NULL;
};
#endif // DATABASECLASS_H
databaseclass.cpp
#include "databaseclass.h"
//構(gòu)造函數(shù)
DatabaseClass::DatabaseClass(){}
DatabaseClass::~DatabaseClass()
{
if(db.isOpen()){
db.close();
qDebug()<<"數(shù)據(jù)庫(kù)關(guān)閉成功!"<<Qt::endl;
}
}
//建立并連接數(shù)據(jù)庫(kù)
bool DatabaseClass::databaseCreate(QString sqlConnectName, QString databaseDriverName, QString databaseName, QString userName, QString password)
{
//判斷當(dāng)前數(shù)據(jù)庫(kù)是否已包括默認(rèn)的連接名稱(chēng)
if(QSqlDatabase::contains(sqlConnectName)){
db=QSqlDatabase::database(sqlConnectName);
qDebug()<<"數(shù)據(jù)庫(kù)使用默認(rèn)連接名稱(chēng)!"<<sqlConnectName<<Qt::endl;
}else {
db=QSqlDatabase::addDatabase(databaseDriverName);
db.setDatabaseName(databaseName);
db.setUserName(userName);
db.setPassword(password);
qDebug()<<":"<<"數(shù)據(jù)庫(kù)使用自定義的連接名稱(chēng)"<<databaseName<<Qt::endl;
}
if(db.open(userName,password)){
qDebug()<<":"<<"數(shù)據(jù)打開(kāi)成功!"<<Qt::endl;
//綁定數(shù)據(jù)庫(kù)
sq=QSharedPointer<QSqlQuery>(new QSqlQuery(databaseName));
qDebug()<<"QSqlQuery指定數(shù)據(jù)庫(kù)"<<Qt::endl;
return true;
}
qDebug()<<":"<<"數(shù)據(jù)打開(kāi)失敗: "<<db.lastError()<<Qt::endl;
return false;
}
//建立數(shù)據(jù)庫(kù)表
bool DatabaseClass::createTable(QString createTableSql)
{
if(sq->exec(createTableSql)){
qDebug()<<"建表語(yǔ)句"<<createTableSql<<"執(zhí)行成功"<<Qt::endl;
return true;
}
qDebug()<<"建表語(yǔ)句"<<createTableSql<<"執(zhí)行失敗"<<Qt::endl;
return false;
}
//查詢(xún)數(shù)據(jù),并把數(shù)據(jù)返回存放至動(dòng)態(tài)數(shù)組中
QVector<QString> DatabaseClass::selectData(QString SelectSql)
{
//先清空全局容器
if(vector.size() != 0){
vector.clear();
}
if(sq->exec(SelectSql)){
qDebug()<<"查詢(xún)數(shù)據(jù)成功"<<Qt::endl;
while (sq->next()) {
vector.push_back(sq->value("username").toString());
vector.push_back(sq->value("password").toString());
}
}
return vector;
}
//增加數(shù)據(jù)
bool DatabaseClass::insertData(QString insertSql)
{
if(sq->exec(insertSql)){
qDebug()<<"增加數(shù)據(jù)"<<insertSql<<"執(zhí)行成功"<<Qt::endl;
return true;
}
qDebug()<<"增加數(shù)據(jù)"<<insertSql<<"執(zhí)行失敗"<<Qt::endl;
return false;
}
//修改數(shù)據(jù)
bool DatabaseClass::updateData(QString updateSql)
{
if(sq->exec(updateSql)){
qDebug()<<"修改數(shù)據(jù)"<<updateSql<<"執(zhí)行成功"<<Qt::endl;
return true;
}
qDebug()<<"修改數(shù)據(jù)"<<updateSql<<"執(zhí)行失敗"<<Qt::endl;
return false;
}
//刪除數(shù)據(jù)
bool DatabaseClass::deleteData(QString deleteData)
{
if(sq->exec(deleteData)){
qDebug()<<"刪除數(shù)據(jù)"<<deleteData<<"執(zhí)行成功"<<Qt::endl;
return true;
}
qDebug()<<"刪除數(shù)據(jù)"<<deleteData<<"執(zhí)行失敗"<<Qt::endl;
return false;
}
controller.h
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <QMainWindow>
#include <QPushButton>
class controller : public QMainWindow
{
Q_OBJECT
public:
explicit controller(QWidget *parent = nullptr);
private:
//功能按鈕對(duì)象
QPushButton *HK_camera=NULL; //??当O(jiān)控
QPushButton *Log_analyzing=NULL; //日志分析
QPushButton *Sensor_check=NULL; //感應(yīng)器檢測(cè)
QPushButton *Hardware_operate=NULL; //硬件操作
//頁(yè)面排版對(duì)象
QTabWidget *tabWidget=NULL;
//tab頁(yè)面管理
void QTabWidgetManage();
//tab屬性設(shè)置
void QTabWidgetConfiguration();
private slots:
void tab1();
void tab2();
void tab3();
void tab4();
};
#endif // CONTROLLER_H
controller.cpp
#include "controller.h"
#include "hardwareoperationclass.h"
#include "hk_widget.h"
#include "iodisplayclass.h"
#include "loganalysisclass.h"
#include "qguiapplication.h"
#include <QPoint>
#include <QRect>
#include <QScreen>
#include<QHBoxLayout>
#include<QFormLayout>
#include<QTabBar>
controller::controller(QWidget *parent): QMainWindow{parent}
{
QScreen *sreen=QGuiApplication::primaryScreen(); //獲取主屏幕對(duì)象
QRect rect=sreen->availableGeometry(); //獲取屏幕的可用大小
// const int WIDTH=rect.size().width(); //屏幕的寬
// const int HEIGHT=rect.size().height(); //獲取屏幕的高
// const int X=rect.x();
// const int Y=rect.y();
//設(shè)置窗體的一些屬性
resize(600,600);
setWindowTitle("設(shè)備醫(yī)生-主控制臺(tái)");
setWindowIcon(QIcon(":/main.png"));
// setWindowFlags(windowFlags()&~Qt::WindowMaximizeButtonHint); //禁用窗體的最大化按鈕
// setFixedSize(width(),height()); //直接設(shè)置大小,禁用鼠標(biāo)拖放改變窗體的大小
//qDebug()<<X<<Y<<WIDTH<<HEIGHT<<this->x()<<this->y();
//把當(dāng)前窗體移動(dòng)到屏幕中央
rect=this->frameGeometry();
QPoint centerPoint=sreen->availableGeometry().center();
rect.moveCenter(centerPoint);
this->move(rect.topLeft());
//設(shè)置背景圖片
setStyleSheet("QMainWindow{ background-image: url(:/back3.jpg);}");
//創(chuàng)建widget對(duì)象,用于裝載所有子控件
QWidget *w=new QWidget;
// w->setContentsMargins(width()/4,width()/4,width()/4,width()/4);
//界面根布局:采用水平布局
QHBoxLayout *hBoxLayout=new QHBoxLayout;
//使用表單布局組織功能按鈕與tab頁(yè)面
QGridLayout *gridLayouts=new QGridLayout;
//使用表格控件組織左側(cè)的主菜單按鈕
QGridLayout *gridLayout=new QGridLayout;
//使用tab控件輪流顯示軟件不同的操作頁(yè)面
tabWidget=new QTabWidget;
//初始化按鈕
HK_camera=new QPushButton("海康監(jiān)控");
Log_analyzing=new QPushButton("日志分析");
Sensor_check=new QPushButton("IO監(jiān)視");
Hardware_operate=new QPushButton("硬件操作");
//設(shè)置表格控件之間的水平、垂直間距
gridLayout->setHorizontalSpacing(0);
gridLayout->setVerticalSpacing(0);
gridLayout->addWidget(HK_camera);
gridLayout->addWidget(Log_analyzing);
gridLayout->addWidget(Sensor_check);
gridLayout->addWidget(Hardware_operate);
gridLayouts->setHorizontalSpacing(5);
gridLayouts->setVerticalSpacing(5);
gridLayouts->addLayout(gridLayout,0,0);
gridLayouts->addWidget(tabWidget,0,1);
//全局使用水平布局
hBoxLayout->addLayout(gridLayouts);
//把所有元素全部放到widget中
w->setLayout(hBoxLayout);
//設(shè)置當(dāng)前的widget為中心控件
setCentralWidget(w);
//tab頁(yè)面管理與屬性配置
QTabWidgetManage();
QTabWidgetConfiguration();
//默認(rèn)顯示第一個(gè)頁(yè)面
tabWidget->setCurrentIndex(0);
//綁定信號(hào)與槽
connect(HK_camera,SIGNAL(clicked(bool)),this,SLOT(tab1()));
connect(Log_analyzing,SIGNAL(clicked(bool)),this,SLOT(tab2()));
connect(Sensor_check,SIGNAL(clicked(bool)),this,SLOT(tab3()));
connect(Hardware_operate,SIGNAL(clicked(bool)),this,SLOT(tab4()));
}
//tab頁(yè)面管理
void controller::QTabWidgetManage()
{
//添加??当O(jiān)控頁(yè)面
HK_Widget *hk=new HK_Widget;
tabWidget->addTab(hk,"海康監(jiān)控");
//添加日志分析頁(yè)面
LogAnalysisClass *log=new LogAnalysisClass;
tabWidget->addTab(log,"日志分析");
//添加IO界面
IODisplayClass *io=new IODisplayClass;
tabWidget->addTab(io,"IO監(jiān)視");
//添加硬件操作頁(yè)面
hardwareOperationClass *Hardware=new hardwareOperationClass;
tabWidget->addTab(Hardware,"硬件操作");
}
//tab屬性設(shè)置
void controller::QTabWidgetConfiguration()
{
//設(shè)置tabwidget的一些屬性
tabWidget->setTabsClosable(true);//標(biāo)簽上面顯示關(guān)閉按鈕
tabWidget->setUsesScrollButtons(true);//標(biāo)簽太多時(shí)顯示滾動(dòng)按鈕
//tabWidget->setMovable(true); //設(shè)置tab為可移動(dòng)的
tabWidget->setTabPosition(QTabWidget::North); //標(biāo)簽顯示位置向北
tabWidget->setTabShape(QTabWidget::Rounded);//設(shè)置tab的形狀為原型
//tabWidget->tabBar()->hide();//隱藏標(biāo)簽頭
tabWidget->setTabIcon(0,QIcon(QPixmap(":/login.png")));
tabWidget->setTabIcon(1,QIcon(QPixmap(":/login.png")));
tabWidget->setTabIcon(2,QIcon(QPixmap(":/login.png")));
tabWidget->setTabIcon(3,QIcon(QPixmap(":/login.png")));
}
void controller::tab1()
{
tabWidget->setCurrentIndex(0);
}
void controller::tab2()
{
tabWidget->setCurrentIndex(1);
}
void controller::tab3()
{
tabWidget->setCurrentIndex(2);
}
void controller::tab4()
{
tabWidget->setCurrentIndex(3);
}
hk_widget.h
#ifndef HK_WIDGET_H
#define HK_WIDGET_H
#include <QWidget>
#include<QComboBox>
#include<QLabel>
#include<QLineEdit>
#include<QPushButton>
#include <QMainWindow>
class HK_Widget : public QWidget
{
Q_OBJECT
public:
explicit HK_Widget(QWidget *parent = nullptr);
signals:
private:
QComboBox *ip_comboBox=NULL; //IP地址選擇
QComboBox *username_comboBox=NULL; //用戶(hù)名選擇
QLineEdit *password_lineEdit=NULL;//密碼輸入框
QComboBox *CameraId_comboBox=NULL; //攝像頭選擇
QComboBox *port_comboBox=NULL; //端口號(hào)
QPushButton *videoPriview_button=NULL;//視頻預(yù)覽
QPushButton *videoDownload_button=NULL;//視頻下載
};
#endif // HK_WIDGET_H
hk_widget.cpp
#include "hk_widget.h"
#include "qguiapplication.h"
#include<QFormLayout>
#include <QIcon>
#include <QPoint>
#include <QScreen>
HK_Widget::HK_Widget(QWidget *parent)
: QWidget{parent}
{
QScreen *sreen=QGuiApplication::primaryScreen(); //獲取主屏幕對(duì)象
QRect rect=sreen->availableGeometry(); //獲取屏幕的可用大小
//控件背景顏色
QString colors="background-color: rgb(170, 170, 0);";
QString blue="background-color: rgb(0, 170, 127);";
//使用表單控件組織參數(shù)設(shè)置
QFormLayout *formLayout=new QFormLayout;
//屬性配置標(biāo)簽
QLabel *sets=new QLabel("屬性選擇頁(yè)面");
sets->setStyleSheet(colors);
sets->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter );
//創(chuàng)建IP標(biāo)簽
QLabel *ip=new QLabel("ip 地址:");
//ip->setStyleSheet(colors);
//實(shí)例化IP下拉框
ip_comboBox=new QComboBox;
ip_comboBox->addItem("192.168.2.105");
//創(chuàng)建用戶(hù)名標(biāo)簽
QLabel *name=new QLabel("用 戶(hù) 名: ");
//name->setStyleSheet(colors);
//實(shí)例化用戶(hù)名下拉框
username_comboBox=new QComboBox;
username_comboBox->addItem("admin");
username_comboBox->addItem("meituan");
//創(chuàng)建密碼標(biāo)簽
QLabel *password=new QLabel("密 碼:");
//password->setStyleSheet(colors);
//實(shí)例化密碼輸入框
password_lineEdit=new QLineEdit;
password_lineEdit->setEchoMode(QLineEdit::Password); //顯示模式設(shè)置為密碼模式
//創(chuàng)建攝像頭選擇標(biāo)簽
QLabel *camera=new QLabel("攝像頭選擇:");
//camera->setStyleSheet(colors);
//實(shí)例化攝像頭選擇下拉框
CameraId_comboBox=new QComboBox;
CameraId_comboBox->addItem("頂部攝像頭");
CameraId_comboBox->addItem("內(nèi)部攝像頭");
CameraId_comboBox->addItem("前部攝像頭");
//創(chuàng)建端口號(hào)標(biāo)簽
QLabel *port=new QLabel("端 口 號(hào) :");
//port->setStyleSheet(colors);
//實(shí)例化端口號(hào)選擇下拉框,添加幾個(gè)不易重復(fù)的端口號(hào)
port_comboBox=new QComboBox;
port_comboBox->addItem("8000");
port_comboBox->addItem("9999");
port_comboBox->addItem("12900");
//視頻下載與視頻預(yù)覽按鈕實(shí)例化
videoPriview_button=new QPushButton("視 頻 預(yù) 覽");
videoDownload_button=new QPushButton("視 頻 下 載");
//把標(biāo)簽、下拉框、輸入框、按鈕分別加入到表單布局中
formLayout->addRow(sets);
formLayout->addRow(ip,ip_comboBox);
formLayout->addRow(name,username_comboBox);
formLayout->addRow(password,password_lineEdit);
formLayout->addRow(camera,CameraId_comboBox);
formLayout->addRow(port,port_comboBox);
formLayout->addRow(videoPriview_button);
formLayout->addRow(videoDownload_button);
setLayout(formLayout);
}
loganalysisclass.h
#ifndef LOGANALYSISCLASS_H
#define LOGANALYSISCLASS_H
#include <QWidget>
class LogAnalysisClass : public QWidget
{
Q_OBJECT
public:
explicit LogAnalysisClass(QWidget *parent = nullptr);
signals:
};
#endif // LOGANALYSISCLASS_H
loganalysisclass.cpp
#include "loganalysisclass.h"
LogAnalysisClass::LogAnalysisClass(QWidget *parent)
: QWidget{parent}
{
}
iodisplayclass.h
#ifndef IODISPLAYCLASS_H
#define IODISPLAYCLASS_H
#include <QWidget>
class IODisplayClass : public QWidget
{
Q_OBJECT
public:
explicit IODisplayClass(QWidget *parent = nullptr);
signals:
};
#endif // IODISPLAYCLASS_H
iodisplayclass.cpp
#include "iodisplayclass.h"
IODisplayClass::IODisplayClass(QWidget *parent)
: QWidget{parent}
{
}
hardwareoperationclass.h
#ifndef HARDWAREOPERATIONCLASS_H
#define HARDWAREOPERATIONCLASS_H
#include <QWidget>
class hardwareOperationClass : public QWidget
{
Q_OBJECT
public:
explicit hardwareOperationClass(QWidget *parent = nullptr);
signals:
};
#endif // HARDWAREOPERATIONCLASS_H
hardwareoperationclass.cpp
#include "hardwareoperationclass.h"
hardwareOperationClass::hardwareOperationClass(QWidget *parent)
: QWidget{parent}
{
}
四 測(cè)試驗(yàn)證
運(yùn)行工程,首次進(jìn)入登錄、注冊(cè)頁(yè)面,
?
程序一開(kāi)始是沒(méi)有賬號(hào)密碼的,需要注冊(cè)一下,在注冊(cè)頁(yè)面輸入用戶(hù)名與密碼時(shí),用一個(gè)空格隔開(kāi),
?輸入用戶(hù)名與密碼后點(diǎn)擊OK,注冊(cè)成功后用剛剛注冊(cè)的賬號(hào)密碼登錄,
?
?登錄成功后,進(jìn)入主控頁(yè)面,
在點(diǎn)擊左側(cè)的功能按鈕時(shí),右側(cè)的頁(yè)面會(huì)切換到對(duì)應(yīng)的功能主頁(yè)。
五 項(xiàng)目工程打包發(fā)布
項(xiàng)目的打包發(fā)布,我們使用qt自帶的打包工具 windeployqt ,操作步驟:
1,把工程文件切換為發(fā)布模式 release,然后執(zhí)行程序,接著找到當(dāng)前工程目錄所在路徑下release之后的可執(zhí)行文件 ,在windows系統(tǒng)下是.exe文件。
?
把這個(gè)exe文件復(fù)制到一個(gè)空的文件夾,如在桌面新建一個(gè)demo的文件,然后把.exe文件復(fù)制到demo文件夾下面,
?
在程序菜單找到qt 64位命令控制臺(tái),
打開(kāi)控制臺(tái)后,執(zhí)行指令 指令 cd/d?C:\Users\11010\Desktop\demo 切換到.exe所在文件夾demo下,?接著執(zhí)行命令?windeployqt gui_1_loginGui.exe 開(kāi)始尋找依賴(lài),
?等待依賴(lài)尋找完成后,直接雙擊exe文件即可執(zhí)行,如果需要發(fā)布給其他人使用,直接把demo文件夾一起發(fā)過(guò)去即可,不過(guò)也可以作成安裝包的形式發(fā)布,這個(gè)后面慢慢講解!
六 項(xiàng)目完整源碼獲取
源代碼下載地址:https://download.csdn.net/download/XiaoWang_csdn/87704416文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-604047.html
源代碼clone地址:git@gitcode.net:XiaoWang_csdn/gui_1_logingui.git文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-604047.html
到了這里,關(guān)于上位機(jī)UI界面設(shè)計(jì)項(xiàng)目的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!