private:....QNetworkAccessManager manager;...
...connect(&manager, SIGNAL(finished(QNetworkReply *)), this, SLOT(replyIsRecieved(QNetworkReply *)));...
manager.get(QNetworkRequest(url));
#ifndef AA_H#define AA_H#include <QObject>#include <QNetworkAccessManager>#include <QNetworkRequest>#include <QDebug>class A : public QObject{ Q_OBJECT QNetworkAccessManager manager;public: A(QObject *parent = 0); ~A(); void doRequest();private slots: void replyIsRecieved(QNetworkReply* reply); };#endif // AA_H
#include "aa.h"A::A(QObject *parent) : QObject(parent){ connect(&manager, SIGNAL(finished(QNetworkReply *)), SLOT(replyIsRecieved(QNetworkReply *)));}A::~A(){}void A::doRequest(){ QNetworkReply *currentReply = manager.get(QNetworkRequest(QUrl("www.ya.ru")));}void A::replyIsRecieved(QNetworkReply* reply){ qDebug() << "OK";}
#ifndef B_H#define B_H#include <QDialog>#include <aa.h>class B : public QObject{ Q_OBJECTpublic: B(QObject *parent = 0, A *man = 0); ~B(); void makeRequest();private: A *requestManager; };#endif // B_H
#include "b.h"B::B(QObject *parent, A *man) : QObject(parent){ requestManager = man;}B::~B(){}void B::makeRequest(){ requestManager->doRequest(); }
#include <QtGui/QApplication>#include <QNetworkAccessManager>#include <QDialog>#include <aa.h>#include <b.h>int main(int argc, char *argv[]){ QApplication a(argc, argv); A reqMan; B wnd(0, &reqMan); wnd.makeRequest(); return a.exec();}