Advertisement
rodrigofbm

Untitled

Jan 8th, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QtCore/QUrl>
  4. #include <QtNetwork/QNetworkRequest>
  5. #include <QtNetwork/QNetworkReply>
  6. #include <QJsonDocument>
  7. #include <QJsonObject>
  8. #include <QMessageBox>
  9.  
  10.  
  11.  
  12. MainWindow::MainWindow(QWidget *parent) :
  13.     QMainWindow(parent),
  14.     ui(new Ui::MainWindow)
  15. {
  16.     ui->setupUi(this);
  17.  
  18.  
  19.  
  20.  
  21.  
  22.  
  23.     QEventLoop eventLoop;
  24.     QNetworkAccessManager mgr;
  25.     QObject::connect(&mgr, SIGNAL(finished(QNetworkReply*)), &eventLoop, SLOT(quit()));
  26.     QNetworkRequest req( QUrl( QString("http://localhost:3000/") ) );
  27.     QNetworkReply *reply = mgr.get(req);
  28.     eventLoop.exec();
  29.  
  30.     if (reply->error() == QNetworkReply::NoError) {
  31.             QString strReply = (QString)reply->readAll();
  32.             QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
  33.             QJsonObject jsonObj = jsonResponse.object();
  34.            
  35.            
  36.             delete reply;
  37.         }
  38.     else {
  39.         QMessageBox::critical(this, "ERROR", reply->errorString());
  40.         delete reply;
  41.     }
  42.  
  43. }
  44.  
  45. MainWindow::~MainWindow()
  46. {
  47.     delete ui;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement