-
Notifications
You must be signed in to change notification settings - Fork 11
/
mainwindow.cpp
123 lines (110 loc) · 2.93 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>//设备名字显示
#include <vector>//多个设备数组
#include <QMessageBox>
using namespace std;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
//按钮与按钮之间的逻辑
//查找设备按钮会与combobox, open button, displayLable控件交互
void MainWindow::on_EnumButton_clicked()
{
ui->DisplayLabel->setStyleSheet("border:1px solid black;");
vector< QString > QUserNames;
if( hik.EnumDevices(QUserNames) != MV_OK)
{
QMessageBox::information(this,"异常","查找设备失败");
return;
}
for(size_t i = 0; i < QUserNames.size(); i++)
{
ui->comboBox->addItem(QUserNames[i]);
}
ui->OpenButton->setDisabled(false);
}
//打开设备, 读取当前的combobox
//控件与关闭设备交互
void MainWindow::on_OpenButton_clicked()
{
int nIndex = ui->comboBox->currentIndex();
if ( hik.OpenDevice(nIndex) != MV_OK )
{
QMessageBox::information(this,"异常","打开设备失败");
return;
}
ui->OpenButton->setDisabled(true);
ui->CloseButton->setDisabled(false);
ui->StartGrabbingButton->setDisabled(false);
}
//关闭设备按钮,
//与open button交互
void MainWindow::on_CloseButton_clicked()
{
if(hik.CloseDevice() != MV_OK)
{
QMessageBox::information(this,"异常","关闭设备失败");
return;
}
ui->OpenButton->setDisabled(false);
ui->CloseButton->setDisabled(false);
}
//开始采集
void MainWindow::on_StartGrabbingButton_clicked()
{
HWND MainWndID = (HWND)ui->DisplayLabel->winId();
if( hik.StartGrabbing(MainWndID) != MV_OK)
{
QMessageBox::information(this,"异常","采集设备失败");
return;
}
ui->StartGrabbingButton->setDisabled(true);
ui->StopGrabbingButton->setDisabled(false);
ui->SaveBmpButton->setDisabled(false);
ui->SaveJpgButton->setDisabled(false);
}
void MainWindow::on_StopGrabbingButton_clicked()
{
if( hik.StopGrabbing() != MV_OK)
{
QMessageBox::information(this,"异常","关闭采集失败");
return;
}
ui->StartGrabbingButton->setDisabled(false);
ui->StopGrabbingButton->setDisabled(true);
}
void MainWindow::on_SaveBmpButton_clicked()
{
if( hik.SaveBmp() != MV_OK)
{
QMessageBox::information(this,"异常","保存bmp失败");
return;
}
else {
QMessageBox::information(this,"成功","保存图片成功");
}
}
//按下触发采集
void MainWindow::on_HardwareRadioButton_clicked()
{
if( hik.SetTriggerMode(1) != MV_OK)
{
QMessageBox::information(this, "异常", "触发采集失败");
}
}
//连续采集
void MainWindow::on_ContinuesRadioButton_clicked()
{
if( hik.SetTriggerMode(0) != MV_OK)
{
QMessageBox::information(this, "异常", "触发采集失败");
}
}