-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientClass.cpp
More file actions
48 lines (39 loc) · 1.22 KB
/
ClientClass.cpp
File metadata and controls
48 lines (39 loc) · 1.22 KB
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
#include "ClientClass.h"
#include "ui_ClientClass.h"
ClientClass::ClientClass(QWidget *parent)
: QDialog(parent)
, ui(new Ui::ClientClass)
{
ui->setupUi(this);
setWindowTitle("Client");
socket = new QTcpSocket(this);
connect(socket, &QTcpSocket::readyRead, this, &ClientClass::readsocket);
ConnectToServer();
}
ClientClass::~ClientClass()
{
delete ui;
}
void ClientClass::ConnectToServer() {
socket->connectToHost("192.168.1.5", 9001); // Replace with your actual server IP
if (socket->waitForConnected(3000)) {
qDebug() << "Connected to server!";
} else {
qDebug() << "Connection failed:" << socket->errorString();
}
}
void ClientClass::readsocket() {
QByteArray data = socket->readAll();
QString message = QString::fromUtf8(data);
qDebug() << "Received from server:" << message;
}
void ClientClass::on_pushButton_clicked() {
// For now, just log something simple
qDebug() << "Send button clicked!";
QString message = ui->lineEdit->text();
qDebug() << "The written message was: " << message;
welcomePage = new WelcomePage();
welcomePage->show();
this->hide();
// You can add logic here later to send a message to the server
}