#include "mainwindow.h"
#include "ui_mainwindow.h"
mainwindow::mainwindow(QWidget *parent) :
QWidget(parent),
ui(new Ui::mainwindow)
{
ui->setupUi(this);
Init();
ConTo();
}
mainwindow::~mainwindow() //析构
{
delete ui;
}
//初始化
void mainwindow::Init()
{
this->BUFSIZE = 614400;
this->conbool = 0;
this->myhp = new http(this);
this->socket = new QTcpSocket(this);
this->socket_env = new QTcpSocket(this);
this->myNet = new connet();
this->rcama = new recamara();
this->rcama->hide();
this->movie = new QMovie(":/picture/robort.gif");
this->player = new QMediaPlayer(this);
player->setVolume(100);
this->rCoder = new recorder(this);
this->myNet->hide();
this->setWindowTitle("智能管家");
this->setWindowIcon(QIcon(":/picture/icon.png"));
ui->robotLabel->setMovie(movie);
ui->robotLabel->setScaledContents(true);
ui->camaLabel->setScaledContents(true);
movie->start();
}
//连接信号与槽
void mainwindow::ConTo()
{
connect(this->myNet,SIGNAL(commited()), this, SLOT(conOver()));
QObject::connect(this->socket, &QTcpSocket::readyRead, this, &mainwindow::readData);
QObject::connect(this->socket_env, &QTcpSocket::readyRead, this, &mainwindow::readData_env);
QObject::connect(this->myhp, SIGNAL(anwser()), this, SLOT(identify()));
}
void mainwindow::on_conButton_clicked()//点击连接
{
if(0 == conbool){
ui->conButton_2->setIcon(QIcon(":/picture/conout1.png"));
this->myNet->show();
}
else{
ui->conButton_2->setIcon(QIcon(":/picture/conout1.png"));
conbool = 0;
this->socket->disconnectFromHost();
this->socket_env->disconnectFromHost();
}
}
//连接完成
void mainwindow::conOver()
{
this->socket->connectToHost(this->myNet->myIp,this->myNet->myPort);
this->socket_env->connectToHost(this->myNet->myIp, this->myNet->myPort1);
ui->conButton_2->setIcon(QIcon(":/picture/conin1.png"));
conbool=1;
}
//发送数据
void mainwindow::sendData(char type, QString name, QString data)
{
QString text = "";
text.append(type);
text.append('#');
text.append(&name);
text.append('#');
text.append(&data);
this->socket_env->write(data.toUtf8());
qDebug()<<"发送:"<<data;
}
//读取数据
void mainwindow::readData()
{
static QByteArray BUF;
static QByteArray buf;
//读取数据
buf = socket->readAll();
//加入缓存
if( (BUF.size()+buf.size()) >=614400 )
{
int len = 614400-BUF.size();
BUF.append(buf.mid(0, len));
this->flushcam(BUF);
buf.remove(0, len);
BUF.clear();
BUF = buf;
qDebug()<<"获得一张图片";
}
else {
BUF.append(buf);
}
}
//环境数据
void mainwindow::readData_env()
{
static QByteArray buf_env;
//接收数据
buf_env = this->socket_env->readAll();
qDebug()<<"环境数据:"<<buf_env;
//刷新环境参数
this->flushenv(buf_env);
}
void mainwindow::on_conButton_2_clicked()
{
on_conButton_clicked();
}
//开关灯
void mainwindow::on_lightbitton_clicked()
{
player->setMedia(QUrl::fromLocalFile("../SmartHome/sound/button.wav"));
player->play();
static int openlight = 0;
if(0 == openlight){
ui->lightlabel->setPixmap(QPixmap(":/picture/lighton.png"));
ui->lightbitton->setText("OFF");
openlight = 1;
//开灯
sendData('w', "wind", "M0CMD00");
}
else {
ui->lightlabel->setPixmap(QPixmap(":/picture/lightoff.png"));
ui->lightbitton->setText("ON");
openlight = 0;
//关灯
sendData('w', "wind", "M0CMD01");
}
}
//开关风扇
void mainwindow::on_windbutton_clicked()
{
player->setMedia(QUrl::fromLocalFile("../SmartHome/sound/button.wav"));
player->play();
static int openwind = 0;
if(0 == openwind){
ui->windlabel->setPixmap(QPixmap(":/picture/windon.png"));
ui->windbutton->setText("OFF");
openwind = 1;
//开风扇
sendData('w', "wind", "M0CMD04");
}
else {
ui->windlabel->setPixmap(QPixmap(":/picture/windoff.png"));
ui->windbutton->setText("ON");
openwind = 0;
//关风扇
sendData('w', "wind", "M0CMD08");
}
}
//开关摄像头
void mainwindow::on_camarabutton_clicked()
{
player->setMedia(QUrl::fromLocalFile("../SmartHome/sound/button.wav"));
player->play();
static int opencamara = 0;
if(0 == opencamara){
ui->camaralabel->setPixmap(QPixmap(":/picture/camaraon.png"));
ui->camarabutton->setText("OFF");
opencamara = 1;
//开摄像头
sendData('w', "wind", "V412C00");
}
else {
ui->camaralabel->setPixmap(QPixmap(":/picture/camaraoff.png"));
ui->camarabutton->setText("ON");
ui->camaLabel->setPixmap(QPixmap(":/picture/backimg.jpg"));
this->rcama->label->setPixmap(QPixmap(":/picture/backimg.jpg"));
opencamara = 0;
//关摄像头
sendData('w', "wind", "V412C01");
}
}
//开关蜂鸣器
void mainwindow::on_alarmbutton_clicked()
{
player->setMedia(QUrl::fromLocalFile("../SmartHome/sound/button.wav"));
player->play();
static int openalarm = 0;
if(0 == openalarm){
ui->alarmlabel_2->setPixmap(QPixmap(":/picture/alarmon.png"));
ui->alarmbutton->setText("OFF");
openalarm = 1;
//开
sendData('w', "wind", "M0CMD02");
}
else {
ui->alarmlabel_2->setPixmap(QPixmap(":/picture/alarmoff.png"));
ui->alarmbutton->setText("ON");
openalarm = 0;
//关
sendData('w', "wind", "M0CMD03");
}
}
//放大摄像头
void mainwindow::on_resizebutton_clicked()
{
this->rcama->show();
}
//居家娱乐
void mainwindow::on_pushButton_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://www.hao5.net/001.htm")));
}
void mainwindow::on_pushButton_2_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("https://www.kugou.com/yy/rank/home/1-8888.html?from=rank")));
}
void mainwindow::on_pushButton_3_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://www.4399.com/")));
}
void mainwindow::on_pushButton_4_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://life.hao123.com/menu")));
}
void mainwindow::on_pushButton_10_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://www.cnkang.com/video/article/n_8269.html")));
}
void mainwindow::on_pushButton_9_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://ds.eywedu.com/")));
}
void mainwindow::on_pushButton_12_clicked(){
QDesktopServices::openUrl(QUrl(QLatin1String("http://ds.eywedu.com/")));
}
//系统维护
void mainwindow::on_pushButton_11_clicked()
{
QMessageBox::about(this, "关于智能管家", "软件名:智能管家系统\n版本号:2.1.0版本\n技术支持:715142109(qq群)\n版权所有:地球村科技有限公司\npowered by:NoMi");
}
//刷新监控
void mainwindow::flushcam(QByteArray buffer)
{
//播放图片,实现两个地方的图片播放
ui->camaLabel->setPixmap(QPixmap::fromImage(QImage::fromData(buffer)));
this->rcama->label->setPixmap(QPixmap::fromImage(QImage::fromData(buffer)));
}
//刷新环境参数
void mainwindow::flushenv(QString env)
{
QString T = env.mid(1, 4);
T.append("℃");
QString H = env.mid(6, 4);
T.append("%");
QString L = env.mid(25, 4);
L.append("cd");
QString A = env.mid(17, 3);
A.append("v");
//更新检测数据
ui->temprLabel->setText(T);
ui->waterlabel->setText(H);
ui->li
没有合适的资源?快使用搜索试试~ 我知道了~
毕设&课程作业_基于Qt编写的智能管家系统客户端,实现语音识别,按钮音效,摄像头采集。.zip
共20个文件
cpp:6个
h:5个
ui:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 22 浏览量
2024-01-31
16:08:20
上传
评论
收藏 17KB ZIP 举报
温馨提示
计算机类毕业设计、课程作业,系统源码!!! 计算机类毕业设计、课程作业,系统源码!!! 计算机类毕业设计、课程作业,系统源码!!!
资源推荐
资源详情
资源评论
收起资源包目录
毕设&课程作业_基于Qt编写的智能管家系统客户端,实现语音识别,按钮音效,摄像头采集。.zip (20个子文件)
Graduation Design
mainwindow.h 2KB
recamara.cpp 643B
SmartHome.pro 2KB
.gitattributes 66B
connet.ui 3KB
recamara.ui 1KB
mainwindow.cpp 10KB
recorder.cpp 1KB
connet.h 454B
http.cpp 3KB
main.cpp 392B
recamara.h 486B
mainwindow.ui 29KB
SmartHome.pro.user 24KB
connet.cpp 746B
.gitignore 270B
res.qrc 1KB
recorder.h 499B
http.ui 399B
http.h 858B
共 20 条
- 1
资源评论
学术菜鸟小晨
- 粉丝: 1w+
- 资源: 4941
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功