#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
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
软件开发设计:PHP、QT、应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、C#等语言的项目开发与学习资料 硬件与设备:单片机、EDA、proteus、RTOS、包括计算机硬件、服务器、网络设备、存储设备、移动设备等 操作系统:LInux、IOS、树莓派、安卓开发、微机操作系统、网络操作系统、分布式操作系统等。此外,还有嵌入式操作系统、智能操作系统等。 网络与通信:数据传输、信号处理、网络协议、网络与通信硬件、网络安全网络与通信是一个非常广泛的领域,它涉及到计算机科学、电子工程、数学等多个学科的知识。 云计算与大数据:数据集、包括云计算平台、大数据分析、人工智能、机器学习等,云计算是一种基于互联网的计算方式,通过这种方式,共享的软硬件资源和信息可以按需提供给计算机和其他设备。
资源推荐
资源详情
资源评论
收起资源包目录
基于Qt编写的智能管家系统客户端,实现语音识别,按钮音效,摄像头采集。.zip (20个子文件)
cm
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
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功