Skip to content

Commit b93284b

Browse files
添加http
1 parent dc73f39 commit b93284b

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

qt_http/mainwindow.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "mainwindow.h"
22
#include "ui_mainwindow.h"
33

4+
#include "httpreply.h"
5+
#include "http.h"
6+
47
MainWindow::MainWindow(QWidget *parent) :
58
QMainWindow(parent),
69
ui(new Ui::MainWindow)
@@ -12,3 +15,23 @@ MainWindow::~MainWindow()
1215
{
1316
delete ui;
1417
}
18+
19+
void MainWindow::HttpRequest()
20+
{
21+
QUrl url;
22+
url.setUrl("http://localhost:8090/ocr_result");
23+
// auto reply = Http::instance().get(url);
24+
std::string resultJsonStr = "data";
25+
QByteArray body = resultJsonStr.c_str();
26+
QByteArray type = "content-type: text/plain;charset=utf-8";
27+
28+
auto reply = Http::instance().post(url, body, type);
29+
30+
connect(reply, &HttpReply::finished, this, [](auto &reply) {
31+
if (reply.isSuccessful()) {
32+
qDebug() << "Feel the bytes!" << reply.body();
33+
} else {
34+
qDebug() << "Something's wrong here" << reply.statusCode() << reply.reasonPhrase();
35+
}
36+
});
37+
}

qt_http/mainwindow.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define MAINWINDOW_H
33

44
#include <QMainWindow>
5+
#include <httprequest.h>
56

67
namespace Ui {
78
class MainWindow;
@@ -15,6 +16,9 @@ class MainWindow : public QMainWindow
1516
explicit MainWindow(QWidget *parent = nullptr);
1617
~MainWindow();
1718

19+
20+
void HttpRequest();
21+
1822
private:
1923
Ui::MainWindow *ui;
2024
};

qt_http/qt_http.pro

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
#
55
#-------------------------------------------------
66

7-
QT += core gui
7+
QT += core gui network
88

99
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
1010

1111
TARGET = qt_http
1212
TEMPLATE = app
1313

14+
include(./http/http.pri)
15+
1416
# The following define makes your compiler emit warnings if you use
1517
# any feature of Qt which has been marked as deprecated (the exact warnings
1618
# depend on your compiler). Please consult the documentation of the
@@ -22,7 +24,7 @@ DEFINES += QT_DEPRECATED_WARNINGS
2224
# You can also select to disable deprecated APIs only up to a certain version of Qt.
2325
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
2426

25-
CONFIG += c++11
27+
CONFIG += c++17
2628

2729
SOURCES += \
2830
main.cpp \

0 commit comments

Comments
 (0)