123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- #include "dialog.h"
- #include "ui_dialog.h"
- #include <QTimer> //定时器类
- #include <windows.h>
- #include<iostream>
- #include<qcursor.h>
- Dialog::Dialog(QWidget *parent) :
- QDialog(parent),
- ui(new Ui::Dialog)
- {
- Qt::WindowFlags windowFlag = Qt::Dialog;
- windowFlag |= Qt::WindowMinimizeButtonHint;
- windowFlag |= Qt::WindowMaximizeButtonHint;
- windowFlag |= Qt::WindowCloseButtonHint;
- setWindowFlags(windowFlag);
- ui->setupUi(this);
- QFile file("./prjfiles/cfg/sxkyprj.cfg");//.cfg为文本文件
- QByteArray jsonData;
- if(file.open(QIODevice::ReadOnly)){
- jsonData = file.readAll();
- file.close();
- // QMessageBox::information(this,"正确","打开配置文件正确.");
- }
- else {
- QMessageBox::critical(this,"错误","打开配置文件错误,软件无法正常运行,请联系厂家");//默认是模态的
- return;
- }
- phkcamera = new hkcamera();
- phkcamera->inicamera(jsonData);
- //初始化对话框界面参数
- QStringList list = phkcamera->getallcameralocations();
- ui->LocationcomboBox->addItems(list);
- QString strlocation = list.at(0);
- QJsonObject camerainfoobj = phkcamera->camerainfomap.value(strlocation);
- QString qstrip = camerainfoobj.value("ip").toString();
- // LONG port = camerainfoobj.value("port").toInt();
- QString qstraccount = camerainfoobj.value("account").toString();
- QString qstrpwd = camerainfoobj.value("password").toString();
- ui->IPLineEdit->setText(qstrip);
- ui->AcccountLineEdit->setText(qstraccount);
- ui->PwdLineEdit->setText(qstrpwd);
- phkcamera->m_userid = phkcamera->camerauseridmap.value(qstrip);
- //combobox内容选择变化时触发currentIndexChanged信号,注意这里用Qt4信号槽比较好,避免混淆
- connect(ui->LocationcomboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(onComboxSelect(int)));
- }
- void Dialog::onComboxSelect(int index)
- {
- //获取combobox当前内容
- QString strlocation = ui->LocationcomboBox->currentText();
- QMap<QString, QJsonObject> camerainfomap = phkcamera->camerainfomap;
- QJsonObject camerainfoobj = camerainfomap.value(strlocation);
- QString qstrip = camerainfoobj.value("ip").toString();
- // LONG port = camerainfoobj.value("port").toInt();
- QString qstraccount = camerainfoobj.value("account").toString();
- QString qstrpwd = camerainfoobj.value("password").toString();
- ui->IPLineEdit->setText(qstrip);
- ui->AcccountLineEdit->setText(qstraccount);
- ui->PwdLineEdit->setText(qstrpwd);
- phkcamera->m_userid = phkcamera->camerauseridmap.value(qstrip);
- // QMessageBox::information(this, "title", "your select item is " + text, NULL);
- }
- Dialog::~Dialog()
- {
- delete ui;
- }
- void Dialog::closeEvent ( QCloseEvent* e )
- {
- if( QMessageBox::question(this,
- tr("Quit"),
- tr("Are you sure to quit this application?"),
- QMessageBox::Yes, QMessageBox::No )
- == QMessageBox::Yes){
- e->accept();//不会将事件传递给组件的父组件
- if(nullptr != phkcamera)
- {
- phkcamera->logout();
- delete phkcamera;
- }
- }
- else
- e->ignore();
- }
- //void Dialog::on_pushButton_clicked()
- //{
- //}
- void Dialog::on_OpenButton_clicked()
- {
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- HWND hWnd = (HWND)ui->DisplayLabel->winId(); //成功时,即可实时显示在该label上
- BOOL bdisplaypic = phkcamera->displaypic(hWnd);
- if(!bdisplaypic){
- QApplication::restoreOverrideCursor();
- // QMessageBox::critical(this,"错误","连接相机成功,但预览失败");//默认是模态的
- return;
- }
- ui->OpenButton->setEnabled(false);
- ui->CloseButton->setEnabled(true);
- QApplication::restoreOverrideCursor();
- //QMessageBox::information(this,"成功","预览成功");//默认是模态的
- return;
- }
- void Dialog::on_SavePicButton_clicked()
- {
- //以当前时间作为文件名
- // QDateTime datetime= QDateTime::currentDateTime();//获取系统当前的时间
- // QString strtime = datetime.toString("yyyyMMddhhmmss");//格式化时间
- // QString qstrdir = ui->SavePicDirLineEdit->text();
- // qstrdir = QDir::fromNativeSeparators(qstrdir);
- // while(qstrdir.endsWith('/')) //此处检测 /
- // {
- // qstrdir.chop(1); //删除最后一字节
- // }
- // QString qstrfilename = qstrdir + "/" + strtime + ".jpg";
- // phkcamera->savepic("D:/goafhikimg/20230613173952.jpg");
- // phkcamera->PostRequestWithFile("D:/goafhikimg/test.jpg", "192.168.3.250", 4);
- // QFile file("D:/sxkyprjcfg/sxkyprj.cfg");//.cfg为文本文件
- // QByteArray jsonData;
- // if(file.open(QIODevice::ReadOnly)){
- // jsonData = file.readAll();
- // file.close();
- // }
- // QJsonDocument jsonDocu = QJsonDocument::fromJson(jsonData);
- // if(jsonDocu.isObject()){
- // QJsonObject obj_root = jsonDocu.object();
- // QStringList keys = obj_root.keys();
- // for(auto key : keys){
- // }
- // }
- // if(nullptr == pmqttgoaf){
- // pmqttgoaf = new mqttgoaf();
- // pmqttgoaf->mqttconnect("113.141.93.143", 8893);
- // }
- // else{
- // pmqttgoaf->mqttpublish("topic/camera/alarm", "hello goafmqtt");
- // }
- //
- }
- void Dialog::on_CloseButton_clicked()
- {
- phkcamera->stopdisplaypic();
- // if(nullptr != phkcamera)
- // {
- // phkcamera->logout();
- // delete phkcamera;
- // phkcamera = nullptr;
- // }
- ui->OpenButton->setEnabled(true);
- ui->CloseButton->setEnabled(false);
- }
|