52 lines
871 B
C++
52 lines
871 B
C++
|
#include "mainwindow.h"
|
||
|
#include "ui_mainwindow.h"
|
||
|
#include "connect.h"
|
||
|
#include <QTcpSocket>
|
||
|
#include <QTextStream>
|
||
|
#include <QString>
|
||
|
|
||
|
MainWindow::MainWindow(QWidget *parent):
|
||
|
QMainWindow(parent),
|
||
|
ui(new Ui::MainWindow)
|
||
|
{
|
||
|
ui->setupUi(this);
|
||
|
mSocket = new QTcpSocket(this);
|
||
|
|
||
|
connect(mSocket, &QTcpSocket::readyRead, [&](){
|
||
|
QTextStream T(mSocket);
|
||
|
auto text = T.readAll();
|
||
|
ui->read->append(text);
|
||
|
});
|
||
|
|
||
|
}
|
||
|
|
||
|
MainWindow::~MainWindow()
|
||
|
{
|
||
|
delete ui;
|
||
|
}
|
||
|
|
||
|
|
||
|
void MainWindow::on_connect_clicked()
|
||
|
{
|
||
|
Connect C(this);
|
||
|
if(C.exec() == QDialog::Rejected)
|
||
|
{
|
||
|
return;
|
||
|
}
|
||
|
mSocket->connectToHost(C.Host(), C.Port());
|
||
|
|
||
|
}
|
||
|
|
||
|
void MainWindow::on_file_clicked()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
|
||
|
void MainWindow::on_send_clicked()
|
||
|
{
|
||
|
QTextStream T(mSocket);
|
||
|
T << ui->name->text() <<": " << ui->message->text();
|
||
|
mSocket->flush();
|
||
|
ui->message->clear();
|
||
|
}
|