I have a class (RequestHandler) that I call from my main Application class to call various web services. Once a service has completed the class sends a Signal back to the calling class to say that it has finished(possibly with QString message). I have the Signal working in a test method but the QNetworkAccessManager is not working at all. I am quite new to QT and C++. Thanks for your help.
// RequestHandler.h
#ifndef REQUESTHANDLER_H_
#define REQUESTHANDLER_H_
#include <QNetworkAccessManager>
#include <QUrl>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QOBJECT>
#include "MainAppClass.hpp"
class RequestHandler : public QObject
{
Q_OBJECT
public:
explicit RequestHandler(QObject *parent = 0);
void validateRegistration(QString reg);
void onStatusUpdateCompleted();
void sayHi();
signals:
void sendSignal(QString txt);
private:
QNetworkAccessManager* manager;
QObject* thisObj;
public slots:
void onRequestCompleted();
};
#endif /* REQUESTHANDLER_H_ */
RequestHandler.cpp
#include "RequestHandler.h"
RequestHandler::RequestHandler(QObject *parent) : QObject(parent)
{
thisObj= parent;
}
void RequestHandler::validateRegistration(QString reg) {
QNetworkRequest request;
request.setUrl(QUrl("the_registration_url"));
manager = new QNetworkAccessManager();
QNetworkReply *reply = manager->get(request);
connect(reply, SIGNAL(finished()), this, SLOT(onRequestCompleted()));
}
void RequestHandler::onRequestCompleted() {
// not getting here at all
}
void RequestHandler::sayHi()
{
// this is working
QObject::connect(this, SIGNAL(sendSignal(QString)), thisCellCast, SLOT(recieveValue(QString)));
emit sendSignal("HERES THE SIGNAL");
}
I am calling this class like this:
// test slots and reg
RequestHandler rh(this);
//working
rh.sayHi();
// not working
rh.validateRegistration("test");
Thanks for your help.