55 lines
935 B
C++
55 lines
935 B
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
#include "connect.h"
|
|
#include <QTcpSocket>
|
|
#include <QTextStream>
|
|
#include <QString>
|
|
#include "directory.h"
|
|
|
|
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()
|
|
{
|
|
directory d;
|
|
d.setModal(true);
|
|
d.exec();
|
|
}
|
|
|
|
void MainWindow::on_send_clicked()
|
|
{
|
|
QTextStream T(mSocket);
|
|
T << ui->name->text() <<": " << ui->message->text();
|
|
mSocket->flush();
|
|
ui->message->clear();
|
|
}
|