forked from jacksonliam/mjpg-streamer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmainwindow.cpp
50 lines (43 loc) · 1.56 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QRegExpValidator *v = new QRegExpValidator(this);
QRegExp rx("((1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})\\.){3,3}(1{0,1}[0-9]{0,2}|2[0-4]{1,1}[0-9]{1,1}|25[0-5]{1,1})");
v->setRegExp(rx);
ui->lineEditServer->setValidator(v);
socket = new QUdpSocket(this);
connect(socket, SIGNAL(connected()), this, SLOT(socketConnected()));
connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(socketError(QAbstractSocket::SocketError)));
connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)), this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
socket->connectToHost(QHostAddress(ui->lineEditServer->text()), ui->spinBoxPort->value(), QUdpSocket::ReadWrite);
}
void MainWindow::socketConnected()
{
ui->labelStatus->setText("Connected");
ui->pushButton->setEnabled(false);
socket->write(ui->lineEditFileName->text().toAscii());
socket->close();
}
void MainWindow::socketStateChanged(QAbstractSocket::SocketState state)
{
if (state == QAbstractSocket::UnconnectedState) {
ui->labelStatus->setText("File saved");
ui->pushButton->setEnabled(true);
}
}
void MainWindow::socketError(QAbstractSocket::SocketError err)
{
ui->labelStatus->setText(QString("Error: %1").arg(err));
ui->pushButton->setEnabled(true);
}