-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmainwindow.cpp
74 lines (58 loc) · 2.05 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
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
, socket(new QSslSocket)
{
ui->setupUi(this);
ui->statusbar->showMessage("Unconnected");
//ui->statusbar->insertPermanentWidget(0,QPixmap())
connect(this->socket,SIGNAL(connected()),this,SLOT(connectedSlot()));
connect(this->socket,SIGNAL(disconnected()),this,SLOT(disconnectedSlot()));
connect(this->socket,SIGNAL(error(QAbstractSocket::SocketError)),this,SLOT(errorSlot(QAbstractSocket::SocketError)));
connect(this->socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)),this,SLOT(stateChangedSlot(QAbstractSocket::SocketState)));
connect(this->socket, SIGNAL(encrypted()),this, SLOT(encryptedSlot()));
connect(this->socket, SIGNAL(sslErrors(const QList<QSslError> &)),this, SLOT(sslErrorsSlot(const QList<QSslError> &)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_button_connect_clicked()
{
//this->socket->ignoreSslErrors();
this->socket->connectToHostEncrypted(ui->ip->text(),ui->port->text().toUInt());
}
void MainWindow::connectedSlot()
{
ui->log->append("Connected successfully [socket descriptor: " + QString::number(this->socket->socketDescriptor()) + "]");
ui->statusbar->showMessage("Connected");
}
void MainWindow::disconnectedSlot()
{
ui->log->append("Disconnected");
ui->statusbar->showMessage("Disconnected");
}
void MainWindow::errorSlot(QAbstractSocket::SocketError e)
{
ui->log->append("Error [" + QString::number(e) + "]: " + this->socket->errorString());
}
void MainWindow::stateChangedSlot(QAbstractSocket::SocketState s)
{
ui->log->append("State: " + QString::number(s));
}
void MainWindow::encryptedSlot()
{
ui->log->append("Connection is encrypted");
}
void MainWindow::sslErrorsSlot(const QList<QSslError> &errors)
{
for(const QSslError& e : errors){
ui->log->append("SSL Error: " + e.errorString());
}
}
void MainWindow::on_button_send_clicked()
{
qDebug() << this->socket->isEncrypted();
}