-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtcpclient.cpp
More file actions
42 lines (31 loc) · 1.07 KB
/
tcpclient.cpp
File metadata and controls
42 lines (31 loc) · 1.07 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
#include "tcpclient.h"
#include <QHostAddress>
TcpClient::TcpClient(QObject *parent) : QObject(parent) {
}
void TcpClient::initialize() {
socket_ = new QTcpSocket(this);
connect(socket_, SIGNAL(connected()), this, SLOT(connected()));
connect(socket_, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(socket_, SIGNAL(readyRead()), this, SLOT(readyRead()));
connect(socket_, SIGNAL(bytesWritten(qint64)), this, SLOT(bytesWritten(qint64)));
qDebug() << "Connecting,..";
socket_->connectToHost(QHostAddress::LocalHost, 1234);
}
void TcpClient::connected() {
qDebug() << "Connected!";
}
void TcpClient::disconnected() {
qDebug() << "Disconnected!";
}
void TcpClient::bytesWritten(qint64 bytes) {
qDebug() << "We wrote: " << bytes;
}
void TcpClient::readyRead() {
qDebug() << "Reading...";
msg_ = QString::fromUtf8(socket_->readAll());
emit receivedMessage(msg_);
}
void TcpClient::onSendMessage(const QString& _text) {
qDebug() << "Writing...";
socket_->write(_text.toUtf8());
}