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. Cannot get data from HTTP request
Qt 6.11 is out! See what's new in the release blog

Cannot get data from HTTP request

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 5 Posters 3.6k Views 3 Watching
  • 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.
  • SGaistS SGaist

    The name of the class containing the signal, same goes for the last parameter, it's the name of the class containing the slot.

    T Offline
    T Offline
    t0msk
    wrote on last edited by t0msk
    #11

    @SGaist

    Changed it to this:

    connect(
            reply, &QNetworkReply::finished,
            this, &Manager::replyFinished
        );
    

    And I get:

    /usr/include/qt/QtCore/qobject.h:243: error: static assertion failed: The slot requires more arguments than the signal provides.
      243 |         Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
          |         ^~~~~~~~~~~~~~~~~
    

    Student who loves C/C++

    mrjjM 1 Reply Last reply
    0
    • T t0msk

      @SGaist

      Changed it to this:

      connect(
              reply, &QNetworkReply::finished,
              this, &Manager::replyFinished
          );
      

      And I get:

      /usr/include/qt/QtCore/qobject.h:243: error: static assertion failed: The slot requires more arguments than the signal provides.
        243 |         Q_STATIC_ASSERT_X(int(SignalType::ArgumentCount) >= int(SlotType::ArgumentCount),
            |         ^~~~~~~~~~~~~~~~~
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #12

      @t0msk said in Cannot get data from HTTP request:

      QNetworkReply::finished,

      Well you are mixing the classes/signals.
      The reply's signals is
      https://doc.qt.io/qt-5/qnetworkreply.html#finished
      and have no QNetworkReply* parameter.

      so i think you mean

      connect(
              Manager, &QNetworkAccessManager::finished,
              this, &Manager::replyFinished
          );
      
      T 1 Reply Last reply
      1
      • mrjjM mrjj

        @t0msk said in Cannot get data from HTTP request:

        QNetworkReply::finished,

        Well you are mixing the classes/signals.
        The reply's signals is
        https://doc.qt.io/qt-5/qnetworkreply.html#finished
        and have no QNetworkReply* parameter.

        so i think you mean

        connect(
                Manager, &QNetworkAccessManager::finished,
                this, &Manager::replyFinished
            );
        
        T Offline
        T Offline
        t0msk
        wrote on last edited by
        #13

        @mrjj said in Cannot get data from HTTP request:

        @t0msk said in Cannot get data from HTTP request:

        QNetworkReply::finished,

        Well you are mixing the classes.
        The reply signals is
        https://doc.qt.io/qt-5/qnetworkreply.html#finished
        and have no QNetworkReply* parameter.

        so i think you mean

        connect(
                Manager, &QNetworkAccessManager::finished,
                this, &Manager::replyFinished
            );
        

        Thank you,
        so now I have:

            QSslConfiguration config = QSslConfiguration::defaultConfiguration();
            config.setProtocol(QSsl::TlsV1_2);
            QNetworkAccessManager *manager = new QNetworkAccessManager();
            QNetworkRequest request;
        
        
            request.setHeader(QNetworkRequest::ServerHeader, "application/json");
            request.setSslConfiguration(config);
            request.setUrl(QUrl("https://www.archlinux.org/packages/search/json/?q=dolphin"));
        
            QNetworkReply *reply = manager->get(request);
        
            connect(
                manager, &QNetworkAccessManager::finished,
                this, &Manager::replyFinished
            );
        
            connect(
                manager, &QNetworkAccessManager::sslErrors,
                this, &Manager::replyFinished
            );
        
        void Manager::replyFinished(QNetworkReply *reply)
        {
            qDebug() << reply->readAll();
        
            QString ha = reply->readAll();
        
            QString he;
        }
        

        Still no output and no error :/

        Student who loves C/C++

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #14

          Hi
          Its a bit odd to connect all to the same slot but lets leave it for now.

          now its time to
          check your openSSL support !

          what does
          qDebug() << "i can use HTTPS:" << QSslSocket::supportsSsl();
          qDebug() << "version" << QSslSocket::sslLibraryBuildVersionString();

          say ?

          T 1 Reply Last reply
          1
          • mrjjM mrjj

            Hi
            Its a bit odd to connect all to the same slot but lets leave it for now.

            now its time to
            check your openSSL support !

            what does
            qDebug() << "i can use HTTPS:" << QSslSocket::supportsSsl();
            qDebug() << "version" << QSslSocket::sslLibraryBuildVersionString();

            say ?

            T Offline
            T Offline
            t0msk
            wrote on last edited by
            #15

            @mrjj
            It says:

            i can use HTTPS: true
            version "OpenSSL 1.1.1c  28 May 2019"
            

            Student who loves C/C++

            1 Reply Last reply
            1
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #16

              What version of Qt are you using ?

              One more thing: do these connections prior to calling get.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              T 1 Reply Last reply
              0
              • SGaistS SGaist

                What version of Qt are you using ?

                One more thing: do these connections prior to calling get.

                T Offline
                T Offline
                t0msk
                wrote on last edited by
                #17

                @SGaist Qt version is 5.13.1

                Student who loves C/C++

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  t0msk
                  wrote on last edited by
                  #18

                  So where can be problem? :/

                  Student who loves C/C++

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by SGaist
                    #19

                    Did you move the connection statements as I suggested ?

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    T 1 Reply Last reply
                    0
                    • SGaistS SGaist

                      Did you move the connection statements as I suggested ?

                      T Offline
                      T Offline
                      t0msk
                      wrote on last edited by
                      #20

                      @SGaist I dont know what do you mean

                      Student who loves C/C++

                      JonBJ 1 Reply Last reply
                      0
                      • T t0msk

                        @SGaist I dont know what do you mean

                        JonBJ Offline
                        JonBJ Offline
                        JonB
                        wrote on last edited by JonB
                        #21

                        @t0msk

                        @SGaist wrote

                        Did you move the connection statements as I suggested ?

                        In your code you show:

                            QNetworkReply *reply = manager->get(request);
                        
                            connect(
                                manager, &QNetworkAccessManager::finished,
                                this, &Manager::replyFinished
                            );
                        
                            connect(
                                manager, &QNetworkAccessManager::sslErrors,
                                this, &Manager::replyFinished
                            );
                        

                        You are calling the manager->get(request) before you have connected the signals/slots on manager, which may/will be too late. He is asking you to change over anything like that to

                            connect(
                                manager, &QNetworkAccessManager::finished,
                                this, &Manager::replyFinished
                            );
                        
                            connect(
                                manager, &QNetworkAccessManager::sslErrors,
                                this, &Manager::replyFinished
                            );
                        
                            QNetworkReply *reply = manager->get(request);
                        

                        so you move the connection statements to before the get(request). So we get to see finished or quite possibly errors from the request. In general, you need to set up signals/slots as soon as you create an object (manager here), before you call anything which could raise a signal.

                        1 Reply Last reply
                        4
                        • T Offline
                          T Offline
                          t0msk
                          wrote on last edited by
                          #22

                          Changed it like:

                              connect(
                                  manager, &QNetworkAccessManager::finished,
                                  this, &Manager::replyFinished
                              );
                          
                              connect(
                                  manager, &QNetworkAccessManager::sslErrors,
                                  this, &Manager::replyFinished
                              );
                          
                              QNetworkReply *reply = manager->get(request);
                          

                          and still doesn't work, no error, no reply.

                          Student who loves C/C++

                          1 Reply Last reply
                          0

                          • Login

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