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. How can I get things from website
Qt 6.11 is out! See what's new in the release blog

How can I get things from website

Scheduled Pinned Locked Moved Solved General and Desktop
73 Posts 5 Posters 34.3k Views 1 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by A Former User
    #1

    Hi, i'm using Qt5.5 on my computer.
    I have the website here
    http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=TOUCH&CPKey=Pass

    It will show "update ok".
    This is my code now. here

    I can't get anything from there.
    Did i miss something or need to fix?
    Please Help!

    jsulmJ 1 Reply Last reply
    0
    • V victor wang

      Hi, i'm using Qt5.5 on my computer.
      I have the website here
      http://www1.winmate/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=TOUCH&CPKey=Pass

      It will show "update ok".
      This is my code now. here

      I can't get anything from there.
      Did i miss something or need to fix?
      Please Help!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @victor-wang You have no error handling at all!
      Connect http://doc.qt.io/qt-5/qnetworkreply.html#error-1 to a slot and print the error message.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      3
      • jsulmJ jsulm

        @victor-wang You have no error handling at all!
        Connect http://doc.qt.io/qt-5/qnetworkreply.html#error-1 to a slot and print the error message.

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @jsulm
        You mean to add like this ?

        qDebug()<<QNetworkReply::errorString
        

        But actually it will got error said "cannot call member function 'QString QIODevice::errorString() const" without object "

        what do i need to fix?

        J.HilkJ 1 Reply Last reply
        0
        • V victor wang

          @jsulm
          You mean to add like this ?

          qDebug()<<QNetworkReply::errorString
          

          But actually it will got error said "cannot call member function 'QString QIODevice::errorString() const" without object "

          what do i need to fix?

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @victor-wang

          you give it an object, obviously :-)

          use this and show us the error msg:

          QNetworkRequest request;
          request.setUrl(QUrl("...."));
          
          QNetworkReply *reply = manager->get(request);
          connect(reply, &QNetworkReply::error, [=](QNetworkReply::NetworkError err){
          qDebug() << err;});
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          V 1 Reply Last reply
          4
          • J.HilkJ J.Hilk

            @victor-wang

            you give it an object, obviously :-)

            use this and show us the error msg:

            QNetworkRequest request;
            request.setUrl(QUrl("...."));
            
            QNetworkReply *reply = manager->get(request);
            connect(reply, &QNetworkReply::error, [=](QNetworkReply::NetworkError err){
            qDebug() << err;});
            
            V Offline
            V Offline
            victor wang
            wrote on last edited by
            #5

            @J.Hilk

            I got this error here
            no matching function.

            VRoninV J.HilkJ 2 Replies Last reply
            0
            • V victor wang

              @J.Hilk

              I got this error here
              no matching function.

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by VRonin
              #6

              @victor-wang You just need to open the docs to find the solution: http://doc.qt.io/qt-5/qnetworkreply.html#error-1 instead of &QNetworkReply::error use static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error) or QOverload<(QNetworkReply::NetworkError)>::(&QNetworkReply::error)>

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              4
              • V victor wang

                @J.Hilk

                I got this error here
                no matching function.

                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                @victor-wang
                My bad, QNetworkReply::error is an overloaded function.

                use this:

                connect(networkReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
                    [=](QNetworkReply::NetworkError code){ qDebug() << code; });
                

                taken from the docu


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                JKSHJ 1 Reply Last reply
                3
                • J.HilkJ J.Hilk

                  @victor-wang
                  My bad, QNetworkReply::error is an overloaded function.

                  use this:

                  connect(networkReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
                      [=](QNetworkReply::NetworkError code){ qDebug() << code; });
                  

                  taken from the docu

                  JKSHJ Offline
                  JKSHJ Offline
                  JKSH
                  Moderators
                  wrote on last edited by
                  #8

                  @J.Hilk said in How can I get things from website:

                  connect(networkReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
                      [=](QNetworkReply::NetworkError code){ qDebug() << code; });
                  

                  taken from the docu

                  In Qt 5.7 onwards, you can also use qOverload() (with C++14) or QOverload (C++11), instead of the longer static_cast: http://doc.qt.io/qt-5/qtglobal.html#qOverload

                  connect(networkReply, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error),
                      [=](QNetworkReply::NetworkError code) { qDebug() << code; });
                  

                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                  V 1 Reply Last reply
                  2
                  • JKSHJ JKSH

                    @J.Hilk said in How can I get things from website:

                    connect(networkReply, static_cast<void(QNetworkReply::*)(QNetworkReply::NetworkError)>(&QNetworkReply::error),
                        [=](QNetworkReply::NetworkError code){ qDebug() << code; });
                    

                    taken from the docu

                    In Qt 5.7 onwards, you can also use qOverload() (with C++14) or QOverload (C++11), instead of the longer static_cast: http://doc.qt.io/qt-5/qtglobal.html#qOverload

                    connect(networkReply, qOverload<QNetworkReply::NetworkError>(&QNetworkReply::error),
                        [=](QNetworkReply::NetworkError code) { qDebug() << code; });
                    
                    V Offline
                    V Offline
                    victor wang
                    wrote on last edited by victor wang
                    #9

                    @JKSH @J-Hilk
                    I'm using Qt5.5 so i can't use qOverload on my Qt version.
                    I had changed it but it still got error.
                    This is my code here

                    And this is the error that i got here

                    It's the same error shows no matching function for call.
                    What else should i do ?

                    JKSHJ 1 Reply Last reply
                    0
                    • V victor wang

                      @JKSH @J-Hilk
                      I'm using Qt5.5 so i can't use qOverload on my Qt version.
                      I had changed it but it still got error.
                      This is my code here

                      And this is the error that i got here

                      It's the same error shows no matching function for call.
                      What else should i do ?

                      JKSHJ Offline
                      JKSHJ Offline
                      JKSH
                      Moderators
                      wrote on last edited by JKSH
                      #10

                      @victor-wang said in How can I get things from website:

                      And this is the error that i got here

                      You have a warning message: "lambda expressions only available with -std=c++11 or -std=gnu++11"

                      That means haven't enabled C++11.

                      Add this line to your *.pro file to enable it: CONFIG += C++11

                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                      V 1 Reply Last reply
                      1
                      • JKSHJ JKSH

                        @victor-wang said in How can I get things from website:

                        And this is the error that i got here

                        You have a warning message: "lambda expressions only available with -std=c++11 or -std=gnu++11"

                        That means haven't enabled C++11.

                        Add this line to your *.pro file to enable it: CONFIG += C++11

                        V Offline
                        V Offline
                        victor wang
                        wrote on last edited by victor wang
                        #11

                        @JKSH
                        I can compiled it successfully.
                        But i don't know what this is doing ?
                        I still can't get any information from my Url.

                        This is my code here

                        And this is what i got here

                        I didn't get any error back but also didn't get what i want back either.

                        This is the Url i want to get http://192.168.100.59/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF

                        I should get a file or get a respond that said ok.

                        JKSHJ 1 Reply Last reply
                        0
                        • JKSHJ Offline
                          JKSHJ Offline
                          JKSH
                          Moderators
                          wrote on last edited by
                          #12

                          Please post your code as text, not pictures. Text is much easier to read and search.

                          Anyway, what is inside your replyFinished() function?

                          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                          V 1 Reply Last reply
                          0
                          • JKSHJ JKSH

                            Please post your code as text, not pictures. Text is much easier to read and search.

                            Anyway, what is inside your replyFinished() function?

                            V Offline
                            V Offline
                            victor wang
                            wrote on last edited by victor wang
                            #13

                            @JKSH

                            void MainWindow::replyFinished(QNetworkReply *reply)
                            {
                            qDebug("connect content");
                            QTextCodec *codec=QTextCodec::codecForLocale();
                            int connect_url=reply -> attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
                            qDebug()<<connect_url;
                            qDebug("here");
                            
                            }
                            

                            Sorry, i'm using Qt via Xming and i can't just copy the code to my local computer.
                            I have to type myself.

                            For the picture i just gave you.
                            "connect_url" will print the number 200 out to make sure the Url is connecting successfully.

                            1 Reply Last reply
                            0
                            • V victor wang

                              @JKSH
                              I can compiled it successfully.
                              But i don't know what this is doing ?
                              I still can't get any information from my Url.

                              This is my code here

                              And this is what i got here

                              I didn't get any error back but also didn't get what i want back either.

                              This is the Url i want to get http://192.168.100.59/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF

                              I should get a file or get a respond that said ok.

                              JKSHJ Offline
                              JKSHJ Offline
                              JKSH
                              Moderators
                              wrote on last edited by
                              #14

                              @victor-wang said in How can I get things from website:

                              "connect_url" will print the number 200 out to make sure the Url is connecting successfully.

                              Yes, 200 means "HTTP OK": http://www.restapitutorial.com/httpstatuscodes.html

                              Your code is connecting to the server OK.

                              void MainWindow::replyFinished(QNetworkReply *reply)
                              {
                              qDebug("connect content");
                              QTextCodec *codec=QTextCodec::codecForLocale();
                              int connect_url=reply -> attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
                              qDebug()<<connect_url;
                              qDebug("here");
                              
                              }
                              

                              You need to read the data from the QNetworkReply. Call reply->readAll() to get the data.

                              Also, remember to delete your QNetworkReply after you have finished, or else you will have a memory leak. See the QNetworkReply documentation: http://doc.qt.io/qt-5/qnetworkreply.html

                              @victor-wang said in [How can I get things from website](/topic/77075/how-can-i-get-things-from-

                              I should get a file

                              As I said above, you must call reply->readAll() to get the data. Then, write the data into a file using a QFile.

                              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                              V 1 Reply Last reply
                              2
                              • JKSHJ JKSH

                                @victor-wang said in How can I get things from website:

                                "connect_url" will print the number 200 out to make sure the Url is connecting successfully.

                                Yes, 200 means "HTTP OK": http://www.restapitutorial.com/httpstatuscodes.html

                                Your code is connecting to the server OK.

                                void MainWindow::replyFinished(QNetworkReply *reply)
                                {
                                qDebug("connect content");
                                QTextCodec *codec=QTextCodec::codecForLocale();
                                int connect_url=reply -> attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
                                qDebug()<<connect_url;
                                qDebug("here");
                                
                                }
                                

                                You need to read the data from the QNetworkReply. Call reply->readAll() to get the data.

                                Also, remember to delete your QNetworkReply after you have finished, or else you will have a memory leak. See the QNetworkReply documentation: http://doc.qt.io/qt-5/qnetworkreply.html

                                @victor-wang said in [How can I get things from website](/topic/77075/how-can-i-get-things-from-

                                I should get a file

                                As I said above, you must call reply->readAll() to get the data. Then, write the data into a file using a QFile.

                                V Offline
                                V Offline
                                victor wang
                                wrote on last edited by
                                #15

                                @JKSH
                                you mean i have to add this after the connect function?

                                qDebug()<<reply->readAll();
                                reply->deleteLater();
                                

                                Is that readAll will print the information out?
                                Or i have to using qDebug to print it out?

                                JKSHJ 1 Reply Last reply
                                0
                                • V victor wang

                                  @JKSH
                                  you mean i have to add this after the connect function?

                                  qDebug()<<reply->readAll();
                                  reply->deleteLater();
                                  

                                  Is that readAll will print the information out?
                                  Or i have to using qDebug to print it out?

                                  JKSHJ Offline
                                  JKSHJ Offline
                                  JKSH
                                  Moderators
                                  wrote on last edited by
                                  #16

                                  @victor-wang said in How can I get things from website:

                                  @JKSH
                                  you mean i have to add this after the connect function?

                                  qDebug()<<reply->readAll();
                                  reply->deleteLater();
                                  

                                  I mean you have to add this inside your replyFinished() slot.

                                  Are you familiar with asynchronous programming? Networking is asynchronous. When you call QNetworkAccessManager::get(), it starts downloading. However, it doesn't wait for the download to finish. Instead, QNetworkAccessManager and QNetworkReply WILL emit the finished() signal when the download finishes. So, you can read the downloaded data from inside the connected slot.

                                  Is that readAll will print the information out?
                                  Or i have to using qDebug to print it out?

                                  readAll() gives you the data in a QByteArray. It doesn't print anything. Do you know how to use QByteArray?

                                  qDebug prints to the console.

                                  Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                  V 1 Reply Last reply
                                  0
                                  • JKSHJ JKSH

                                    @victor-wang said in How can I get things from website:

                                    @JKSH
                                    you mean i have to add this after the connect function?

                                    qDebug()<<reply->readAll();
                                    reply->deleteLater();
                                    

                                    I mean you have to add this inside your replyFinished() slot.

                                    Are you familiar with asynchronous programming? Networking is asynchronous. When you call QNetworkAccessManager::get(), it starts downloading. However, it doesn't wait for the download to finish. Instead, QNetworkAccessManager and QNetworkReply WILL emit the finished() signal when the download finishes. So, you can read the downloaded data from inside the connected slot.

                                    Is that readAll will print the information out?
                                    Or i have to using qDebug to print it out?

                                    readAll() gives you the data in a QByteArray. It doesn't print anything. Do you know how to use QByteArray?

                                    qDebug prints to the console.

                                    V Offline
                                    V Offline
                                    victor wang
                                    wrote on last edited by
                                    #17

                                    @JKSH

                                    I am not quite sure that i'm using the right way.
                                    I write this code into replyFinished();

                                    QByteArray output;
                                    output = reply -> readAll();
                                    qDebug()<<output;
                                    reply->deleteLater();
                                    

                                    Am i right?
                                    Sorry i'm new in Qt please be patient to me:(

                                    JKSHJ 1 Reply Last reply
                                    0
                                    • V victor wang

                                      @JKSH

                                      I am not quite sure that i'm using the right way.
                                      I write this code into replyFinished();

                                      QByteArray output;
                                      output = reply -> readAll();
                                      qDebug()<<output;
                                      reply->deleteLater();
                                      

                                      Am i right?
                                      Sorry i'm new in Qt please be patient to me:(

                                      JKSHJ Offline
                                      JKSHJ Offline
                                      JKSH
                                      Moderators
                                      wrote on last edited by
                                      #18

                                      @victor-wang said in How can I get things from website:

                                      I write this code into replyFinished();

                                      QByteArray output;
                                      output = reply -> readAll();
                                      qDebug()<<output;
                                      reply->deleteLater();
                                      

                                      Am i right?

                                      Yes, that is right :)

                                      Now, you can save output into a file, using QFile.

                                      Sorry i'm new in Qt please be patient to me:(

                                      No problem! We are happy to help beginners. I think you are learning well.

                                      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                                      V 1 Reply Last reply
                                      0
                                      • JKSHJ JKSH

                                        @victor-wang said in How can I get things from website:

                                        I write this code into replyFinished();

                                        QByteArray output;
                                        output = reply -> readAll();
                                        qDebug()<<output;
                                        reply->deleteLater();
                                        

                                        Am i right?

                                        Yes, that is right :)

                                        Now, you can save output into a file, using QFile.

                                        Sorry i'm new in Qt please be patient to me:(

                                        No problem! We are happy to help beginners. I think you are learning well.

                                        V Offline
                                        V Offline
                                        victor wang
                                        wrote on last edited by
                                        #19

                                        @JKSH
                                        I this function will show the content out?

                                        qDebug()<<output;
                                        

                                        If it is why it showed NULL on the console. here
                                        I thought it will print the Url information which i had just gave you "Updated ok!".

                                        V 1 Reply Last reply
                                        0
                                        • V victor wang

                                          @JKSH
                                          I this function will show the content out?

                                          qDebug()<<output;
                                          

                                          If it is why it showed NULL on the console. here
                                          I thought it will print the Url information which i had just gave you "Updated ok!".

                                          V Offline
                                          V Offline
                                          victor wang
                                          wrote on last edited by
                                          #20

                                          @victor-wang

                                          I add this after connect instead of replyFinished slot.

                                          file.setFileName("/home/check.txt");
                                          if(!file.exist)qDebug("not exist");
                                          if(!file.open(QIODevice::WriteOny | QIODevice::Text))qDebug("not write success");
                                          stream.setDevice(&file);
                                          stream<<out;
                                          file.close;
                                          

                                          But when i went to cat the check.txt there is nothing in the file.

                                          And i add this in my replyFinished slot.

                                          out=reply->readAll();
                                          qDebug()<<out;
                                          reply->deleteLater();
                                          

                                          The "QByteArray out" i had declared it in the mainwidow.h for global type.
                                          Did i need to put in the private place or the public place in the mainwindow.h?

                                          Why i still didn't see anything in my file?

                                          JKSHJ 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