0

I'm trying to do a simple GET request using QNetworkReply but finished() never get's called, here is my code

QtTest::QtTest(QWidget *parent):QWidget(parent){
  ui.setupUi(this);

  auto network_access_manager = new QNetworkAccessManager(this);
  auto reply = network_access_manager->get(QNetworkRequest(QUrl("http://www.whatsmyip.org/")));
  connect(reply, SIGNAL(finished()), this, SLOT(download_finished()));


qDebug() << "Started";

}

void QtTest::download_finished() {

  qDebug() << "Finished";

}

If I check output on startup I get

QObject::connect: Cannot connect (null)::aboutToQuit() to QNativeWifiEngine::closeHandle()

Exception thrown at 0x749040F8 (KernelBase.dll) in QtTest.exe: 0x000006A6: The binding handle is invalid.
QtTest
  • 1
  • 1
  • Check [this answer](http://stackoverflow.com/a/37926541/1329652) for a complete example and see if it works for you. If it does, you have other problems. If it doesn't, your Qt install is somehow broken/corrupt. – Kuba hasn't forgotten Monica Jul 07 '16 at 14:43
  • For my case, the QtTest was already released before download_finished was called. – Zhang Dec 19 '19 at 02:53

2 Answers2

0

Verify if you are declaring download_finished() as a slot.

class QtTest : public QObject
{
    Q_OBJECT
public:
    QtTest(QObject *parent = 0);

private slots:
    void download_finished();
};
rflobao
  • 562
  • 2
  • 8
-1

change your definition of download_finished to include the reply;

The signal is; finished(QNetworkReply *reply) so

  QtTest::download_finished(QNetworkReply *reply)
  {
     .... etc

Make sure to include the parameter in the connect statement.

john elemans
  • 2,578
  • 2
  • 15
  • 26