#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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
<资源说明> 先看项目说明(如有readme.md),还是不清楚运行或者遇到问题,可私信与我沟通,可远程教学指导 1、该资源内项目源码可直接作为课程设计、毕业设计、课程作业、实训实验等,公司项目可基于此二次开发。 2、代码完整且可成功运行,请放心下载使用!任何问题及时交流 3、本项目适合计算机相关专业学生、高校老师、公司下载学习,也适合小白学习进阶。 4、项目资料齐全,容易复现运行,提供技术支持。
资源推荐
资源详情
资源评论
收起资源包目录
本科毕设-基于C++和QT开发的语音识别的智能管家系统源码.zip (18个子文件)
mainwindow.h 2KB
recamara.cpp 643B
SmartHome.pro 2KB
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
res.qrc 1KB
recorder.h 499B
http.ui 399B
http.h 858B
共 18 条
- 1
资源评论
Scikit-learn
- 粉丝: 4216
- 资源: 1588
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功