class Test_class{public: Test_class::Test_class(); ~Test_class(void);};
Test_class::Test_class(){ qDebug() << "into constructor Test_class"; QNetworkAccessManager *netman = new QNetworkAccessManager(); QObject::connect(netman, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); QNetworkReply* reply = netman->get(QNetworkRequest(QUrl("http://www.ya.ru"))); qDebug() << reply;}
#pragma once#include <QObject>#include <QtNetwork\qnetworkreply.h>class Test_class : public QObject{ Q_OBJECTpublic: Test_class::Test_class(); ~Test_class(void);public slots: //void replyFinished(QNetworkReply* reply); // тот самый слот, который вы подключаете к сигналу finished void finishedSlot(QNetworkReply* reply);};
#include "Test_class.h"#include <QtCore/QCoreApplication>#include <QtNetwork\qnetworkaccessmanager.h>#include <QtNetwork\qnetworkrequest.h>#include <QtNetwork\qnetworkreply.h>#include <qurl.h>#include <QObject>//#include <MultiWidgets/Application.hpp>//#include "httprequest.h"#include <Qt/qdebug.h>Test_class::Test_class(){ qDebug() << "into constructor Test_class"; QNetworkAccessManager *netman = new QNetworkAccessManager(); //QObject::connect(netman, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); netman->get(QNetworkRequest(QUrl("http://www.ya.ru"))); //qDebug() << reply; //connect(netman, SIGNAL(finished(QNetworkReply*)),this, SLOT(replyFinished(QNetworkReply*))); //HttpRequest req; //req.processRequest("www.ya.ru");}Test_class::~Test_class(void){}void Test_class::finishedSlot(QNetworkReply* reply){// // Не произошло-ли ошибки?// if (reply->error() == QNetworkReply::NoError)// {// // Читаем ответ от сервера// QByteArray bytes = reply->readAll();// QString string(bytes);//// // Выводим ответ на экран// qDebug() << string;// }// // Произошла какая-то ошибка// else// {// // обрабатываем ошибку// qDebug() << reply->errorString();// }// delete reply;}