#include "mainwindow.h" #include "ui_mainwindow.h" #include "../server/client.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->lineEdit, SIGNAL(returnPressed()), this, SLOT(handleLineEntered())); m_client = new Client(this); connect(m_client, SIGNAL(consoleOutput(QString)), this, SLOT(handleConsoleOutput(QString))); m_client->connectToHost("localhost", 6744); } MainWindow::~MainWindow() { delete ui; } void MainWindow::handleLineEntered() { QString line = ui->lineEdit->text(); ui->lineEdit->clear(); m_client->consoleInput(line); } void MainWindow::handleConsoleOutput(const QString &str) { QTextCursor cursor = ui->textEdit->textCursor(); bool isAtEnd = cursor.atEnd(); cursor.movePosition(QTextCursor::End); cursor.clearSelection(); cursor.insertText(str); cursor.insertText("\n"); if (isAtEnd) ui->textEdit->setTextCursor(cursor); }