Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt QNetworkAccessManager does not emit signals

Tags:

signals

qt

slot

qt4

The function CheckSite() is called with an url like http://example.com, it initializes a QNetworkAccessManager object and connect() slots and signals.

The manger->get() call seems work (it generates http traffic) but does not call the slot replyFinished() at the request end.

What's wrong with this code?

#include <QtCore>
#include <QtNetwork>

class ClientHandler : public QObject
{
Q_OBJECT
  QNetworkAccessManager *manager;
private slots:
  void replyFinished(QNetworkReply *);
public:
  void CheckSite(QString url);
};

void ClientHandler::replyFinished(QNetworkReply *reply) { qDebug() << "DONE"; }

void ClientHandler::CheckSite(QString url) {
  QUrl qrl(url);
  manager = new QNetworkAccessManager(this);
  connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(replyFinished(QNetworkReply*)));
  manager->get(QNetworkRequest(qrl));
}
like image 255
Emilio Avatar asked Nov 14 '22 11:11

Emilio


1 Answers

Nothing. I wrapped it so it was fully functional and it works fine:

// placed in client.cpp
#include <QtDebug>
#include <QCoreApplication>

/* YOUR CODE */

int main(int argc, char *argv[])
{
        QCoreApplication app(argc, argv);
        ClientHandler handler;
        handler.CheckSite("www.google.com");
        return app.exec();

}

#include "client.moc"

It output "DONE" as expected. Maybe the site you're checking really isn't returning? Maybe it needs authentication or is producing ssl errors?

like image 84
Kaleb Pederson Avatar answered Nov 17 '22 00:11

Kaleb Pederson