-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
43 lines (32 loc) · 1.12 KB
/
mainwindow.cpp
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QNetworkRequest>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
networkManager = new QNetworkAccessManager(this);
connect(ui->submitButton, &QPushButton::clicked, this, &MainWindow::onButtonClicked);
}
MainWindow::~MainWindow() {
delete ui;
}
void MainWindow::onButtonClicked() {
QString data = ui->plainTextEdit->toPlainText();
QUrl url("http://localhost:8080/process");
QNetworkRequest request(url);
request.setHeader(QNetworkRequest::ContentTypeHeader, "text/plain");
QNetworkReply *reply = networkManager->post(request, data.toUtf8());
connect(reply, &QNetworkReply::finished, this, [this, reply]() {
handleNetworkReply(reply);
});
}
void MainWindow::handleNetworkReply(QNetworkReply *reply) {
if (reply->error() == QNetworkReply::NoError) {
QString response = reply->readAll();
ui->label->setText(response);
} else {
ui->label->setText("Error: " + reply->errorString());
}
reply->deleteLater();
}