-
Notifications
You must be signed in to change notification settings - Fork 1
/
connection.cpp
53 lines (46 loc) · 1.41 KB
/
connection.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
#include "connection.h"
#include "ui_connection.h"
#include <QMessageBox>
#include <QtNetwork>
connection::connection(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::connection) {
ui->setupUi(this);
this->setFixedSize(this->size());
}
connection::~connection() {
delete ui;
}
void connection::on_pushButton_3_clicked() {
emit showmain();
this->close();
delete this;
}
void connection::on_pushButton_2_clicked() {
if (con_mode == 1) {
tcpSocket = new QTcpSocket();
tcpSocket->connectToHost(ui->IPaddr->text(), 9888);
if (tcpSocket->waitForConnected(1000)) {
QMessageBox::information(NULL, "提示", "该主机可用");
tcpSocket->write("game start");
localSlave = new local_slave(this);
connect(this, &connection::send_socket, localSlave, &local_slave::get_socket);
connect(localSlave, &local_slave::showmain, this, &connection::show);
emit send_socket(tcpSocket);
localSlave->show();
this->hide();
} else {
QMessageBox::information(NULL, "提示", "连接失败");
tcpSocket->disconnectFromHost();
}
//
}
}
void connection::change_mode(int a) {
con_mode = a;
if (con_mode == 1) {
ui->player_name->setEnabled(false);
ui->port->setEnabled(false);
ui->password->setEnabled(false);
}
}