Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal "finished" of QNetworkManager
QtWS25 Last Chance

Signal "finished" of QNetworkManager

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 4 Posters 848 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    JohK
    wrote on last edited by
    #1

    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
      • if yes: do nothing
        **/
        {
        QString strRequest = "http://fritz.box/login_sid.lua";

      (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

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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()

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • J Offline
        J Offline
        JohK
        wrote on last edited by
        #3

        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

        aha_1980A 1 Reply Last reply
        1
        • J JohK

          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

          aha_1980A Offline
          aha_1980A Offline
          aha_1980
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi @JohK,

          so please mark this topic as SOLVED. Thanks!

          1 Reply Last reply
          0
          • Z Offline
            Z Offline
            zozianoo
            wrote on last edited by zozianoo
            #5
            This post is deleted!
            aha_1980A 1 Reply Last reply
            -1
            • Z zozianoo

              This post is deleted!

              aha_1980A Offline
              aha_1980A Offline
              aha_1980
              Lifetime Qt Champion
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved