Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Signal "finished" of QNetworkManager



  • Hi,
    I tried to have use QNetworkManager to retrieve a information from a server. However it seems the Signal "finished" is not called.
    Here is the source:

    --- Class Implementation

    FritzBox::FritzBox()
    {
    FritzConn.setParent(this);
    connect(&FritzConn, SIGNAL(finished(QNetworkReply*)), this, SLOT(ReadFromFritz(QNetworkReply*)));
    }

    void FritzBox::Connect2Fritz()
    /**

    • Slot that establishes the connection to the Fritzbox by:

      • cheking if a valid SID exists
      • if not, then try to connect to Fritz and get a valid SID
    • (static_cast<MainWindow*>(parent()))->PrintQuery(strRequest);

      Reply = FritzConn.get(QNetworkRequest(QUrl(strRequest)));
      // connect(Reply, SIGNAL(readyRead()), this, SLOT(readyRead()));

    }

    void FritzBox::ReadFromFritz(QNetworkReply Reply)
    /
    *

    • This slot is connected to the TcpClient signal that data is available to read.
    • Upon receiving this signal, the data is read and evaluated.
      /
      {
      QByteArray ReadData = Reply->readAll();
      FritzAnswer = ReadData;
      (static_cast<MainWindow
      >(parent()))->PrintAnswer("Signal Finished");
      (static_cast<MainWindow
      >(parent()))->PrintAnswer(FritzAnswer);

    }

    void FritzBox::readyRead()
    /**

    • This slot is connected to the TcpClient signal that data is available to read.
    • Upon receiving this signal, the data is read and evaluated.
      /
      {
      QByteArray ReadData = Reply->readAll();
      FritzAnswer = ReadData;
      (static_cast<MainWindow
      >(parent()))->PrintAnswer("Signal readyRead");
      (static_cast<MainWindow
      >(parent()))->PrintAnswer(FritzAnswer);

    }

    --- Class Implementation finished

    The method connected to the finished signal is never called. However, if I connect to the "Reply" everything works.

    I looked on the www to search for similiar problems. I found some, but their problem usually was, that the QNetworkManager was destroyed before the answer could be read.

    This is definitely not the case here. This class is instatiated in MainWindow and is always valid.

    So, why is the method connected to the signal "finished" of QNetworkManager not called?

    Thanks,
    Johannes


  • Qt Champions 2019

    @JohK said in Signal "finished" of QNetworkManager:

    void FritzBox::ReadFromFritz(QNetworkReply Reply)

    Is this a typo? QNetworkReply must be a pointer.
    Please use the new Signal/Slot syntax ( https://wiki.qt.io/New_Signal_Slot_Syntax/ ) or check the return value of connect()



  • Hello,
    thanks.

    1. the original line is "void FritzBox::ReadFromFritz(QNetworkReply *Reply)
      The * got somehow lost upon copying the source to the forum. :-(

    2. Now I am using the new syntax and all works.

    I don't know why the original didn't work, but with the new its OK.

    Thanks again,
    Johannes


  • Lifetime Qt Champion

    Hi @JohK,

    so please mark this topic as SOLVED. Thanks!



  • This post is deleted!

  • Lifetime Qt Champion

    This post is deleted!

Log in to reply