Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "ui_mainwindow.h"
- #include <QtCore/QUrl>
- #include <QtNetwork/QNetworkRequest>
- #include <QtNetwork/QNetworkReply>
- #include <QJsonDocument>
- #include <QJsonObject>
- #include <QMessageBox>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- ui->setupUi(this);
- QEventLoop eventLoop;
- QNetworkAccessManager mgr;
- QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
- QNetworkRequest req( QUrl( QString("http://localhost:3000/") ) );
- QNetworkReply *reply = mgr.get(req);
- eventLoop.exec();
- if (reply->error() == QNetworkReply::NoError) {
- QString strReply = (QString)reply->readAll();
- QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
- QJsonObject jsonObj = jsonResponse.object();
- delete reply;
- }
- else {
- QMessageBox::critical(this, "ERROR", reply->errorString());
- delete reply;
- }
- }
- MainWindow::~MainWindow()
- {
- delete ui;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement