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.4k 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.
  • 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
      • V victor wang

        @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 Offline
        JKSHJ Offline
        JKSH
        Moderators
        wrote on last edited by
        #21

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

        I this function will show the content out?

        qDebug()<<output;
        

        Yes.

        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?

        No, no need.

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

        I add this after connect instead of replyFinished slot.

        That definitely won't work, because you haven't received the data yet.

        Remember, networking is asynchronous. You can only read the data after the finished() signal is emitted.

        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!".
        ...
        Why i still didn't see anything in my file?

        This is where you need to start debugging and testing.

        1. What do you get when you type your URL into your browser?
        2. What happens when you change the URL to http://lists.qt-project.org/mailman/listinfo ?
        3. Is your QNetworkRequest constructed correctly?
        4. Is your device on the same subnet as the server?

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

        V 2 Replies Last reply
        2
        • JKSHJ JKSH

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

          I this function will show the content out?

          qDebug()<<output;
          

          Yes.

          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?

          No, no need.

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

          I add this after connect instead of replyFinished slot.

          That definitely won't work, because you haven't received the data yet.

          Remember, networking is asynchronous. You can only read the data after the finished() signal is emitted.

          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!".
          ...
          Why i still didn't see anything in my file?

          This is where you need to start debugging and testing.

          1. What do you get when you type your URL into your browser?
          2. What happens when you change the URL to http://lists.qt-project.org/mailman/listinfo ?
          3. Is your QNetworkRequest constructed correctly?
          4. Is your device on the same subnet as the server?
          V Offline
          V Offline
          victor wang
          wrote on last edited by victor wang
          #22

          @JKSH
          Is that you mean i have to add this QFile function in the replyFinisheed() slot?
          Or i have to do it when the finished signal is up?
          If it is how can i judge the signal and where do i have to add the function in?

          For the first of debugging and testing.
          I will get this on my browser. here

          For the second one, i'm not quite sure what does that mean.

          For third one, what does"QNetworkRequest constructly correctly"mean?
          I thought i am using the library that Qt have already constructed.

          For forth one, I'm sure i am on the same subnet because i can send this commend to my console

          wget http://192.168.100.59/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF
          

          And i will get the file and the content will show "updated ok".

          jsulmJ 1 Reply Last reply
          0
          • JKSHJ JKSH

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

            I this function will show the content out?

            qDebug()<<output;
            

            Yes.

            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?

            No, no need.

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

            I add this after connect instead of replyFinished slot.

            That definitely won't work, because you haven't received the data yet.

            Remember, networking is asynchronous. You can only read the data after the finished() signal is emitted.

            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!".
            ...
            Why i still didn't see anything in my file?

            This is where you need to start debugging and testing.

            1. What do you get when you type your URL into your browser?
            2. What happens when you change the URL to http://lists.qt-project.org/mailman/listinfo ?
            3. Is your QNetworkRequest constructed correctly?
            4. Is your device on the same subnet as the server?
            V Offline
            V Offline
            victor wang
            wrote on last edited by
            #23

            @JKSH
            I had add qDebug() function in replyFinished() slot.
            Here is my code.

            According to what you said it will print something out if i am in the same subnet.
            And i'm sure that i am in the same subnet but why it still print NULL out like this?

            According to the picture i gave you, i assume that it will return "Updated ok!" back to me.

            1 Reply Last reply
            0
            • V victor wang

              @JKSH
              Is that you mean i have to add this QFile function in the replyFinisheed() slot?
              Or i have to do it when the finished signal is up?
              If it is how can i judge the signal and where do i have to add the function in?

              For the first of debugging and testing.
              I will get this on my browser. here

              For the second one, i'm not quite sure what does that mean.

              For third one, what does"QNetworkRequest constructly correctly"mean?
              I thought i am using the library that Qt have already constructed.

              For forth one, I'm sure i am on the same subnet because i can send this commend to my console

              wget http://192.168.100.59/PLMS/TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF
              

              And i will get the file and the content will show "updated ok".

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

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

              Or i have to do it when the finished signal is up?

              @JKSH already said several times that you have to do it in the slot connected to the finished() signal. So, yes do it in when you get finished() signal.
              To your code: you call readAll twice - that is probably the reason why qDebug() << out; prints nothing. You should call readAll only once and then print the data.

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

              V 1 Reply Last reply
              0
              • jsulmJ jsulm

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

                Or i have to do it when the finished signal is up?

                @JKSH already said several times that you have to do it in the slot connected to the finished() signal. So, yes do it in when you get finished() signal.
                To your code: you call readAll twice - that is probably the reason why qDebug() << out; prints nothing. You should call readAll only once and then print the data.

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

                @jsulm
                That mean i have to add QFile function into replyFinished() SLOT right?

                ReadAll function actually it call twice by itself and i don't know why it will happened.
                I'm sure that i just call one time for the ReadAll function.
                This is my code here.

                But when I add it into replyFinished() slot, it cannot connect to server.
                The connect_url will return 0 for the second time to me like this.
                What can i do?

                jsulmJ 1 Reply Last reply
                0
                • V victor wang

                  @jsulm
                  That mean i have to add QFile function into replyFinished() SLOT right?

                  ReadAll function actually it call twice by itself and i don't know why it will happened.
                  I'm sure that i just call one time for the ReadAll function.
                  This is my code here.

                  But when I add it into replyFinished() slot, it cannot connect to server.
                  The connect_url will return 0 for the second time to me like this.
                  What can i do?

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

                  @victor-wang YES
                  "ReadAll function actually it call twice by itself" - how can a function call itself?
                  You do it twice, please check your own code again. First time: line 1999, second time line 2013.

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

                  V 1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @victor-wang YES
                    "ReadAll function actually it call twice by itself" - how can a function call itself?
                    You do it twice, please check your own code again. First time: line 1999, second time line 2013.

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

                    @jsulm
                    Thank you for telling me!
                    But now i still get nothing.
                    I had check several time that i can wget the Url on the console.
                    And i'm sure it is the right subnet and Url.
                    And i checked the check.txt file can be write nor read.
                    Why it still print NULL out?

                    jsulmJ 1 Reply Last reply
                    0
                    • V victor wang

                      @jsulm
                      Thank you for telling me!
                      But now i still get nothing.
                      I had check several time that i can wget the Url on the console.
                      And i'm sure it is the right subnet and Url.
                      And i checked the check.txt file can be write nor read.
                      Why it still print NULL out?

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

                      @victor-wang show your code

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

                      V 1 Reply Last reply
                      0
                      • jsulmJ jsulm

                        @victor-wang show your code

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

                        @jsulm
                        Here is the code for replyFinished() slot.

                        This is where i called the Finished() signal and replyFinished() slot via connect

                        jsulmJ 2 Replies Last reply
                        0
                        • V victor wang

                          @jsulm
                          Here is the code for replyFinished() slot.

                          This is where i called the Finished() signal and replyFinished() slot via connect

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

                          @victor-wang You cannot write in /home! (line 2019)
                          It should be /home/YOUR_USER_NAME/check.txt

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

                          1 Reply Last reply
                          1
                          • V victor wang

                            @jsulm
                            Here is the code for replyFinished() slot.

                            This is where i called the Finished() signal and replyFinished() slot via connect

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

                            @victor-wang What do you get if you use wget with that URL? Any data?

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

                            V 1 Reply Last reply
                            0
                            • jsulmJ jsulm

                              @victor-wang What do you get if you use wget with that URL? Any data?

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

                              @jsulm
                              I will get a file like this.

                              i will get the file called "TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF"

                              And i can use vi to see the content inside like this.

                              I changed the path to /home/root/check.txt still got nothing in it.

                              jsulmJ 1 Reply Last reply
                              0
                              • V victor wang

                                @jsulm
                                I will get a file like this.

                                i will get the file called "TestCheck.asp?LSN=201503003009&EmpId=we9999&CPID=OS&CPKey=95Z0000000AF"

                                And i can use vi to see the content inside like this.

                                I changed the path to /home/root/check.txt still got nothing in it.

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

                                @victor-wang You should print out reply->error()
                                If everything was fine then it should print out 0 (QNetworkReply::NoError)

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

                                V 1 Reply Last reply
                                0
                                • jsulmJ jsulm

                                  @victor-wang You should print out reply->error()
                                  If everything was fine then it should print out 0 (QNetworkReply::NoError)

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

                                  @jsulm
                                  It shows no error.
                                  That means everything was fine.
                                  But why still have nothing?
                                  Is there any possible because i receive a file?

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • V victor wang

                                    @jsulm
                                    It shows no error.
                                    That means everything was fine.
                                    But why still have nothing?
                                    Is there any possible because i receive a file?

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

                                    @victor-wang Is that out variable a QByteArray?
                                    Also, what exactly does qDebug()<<out print out?

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

                                    V 1 Reply Last reply
                                    0
                                    • jsulmJ jsulm

                                      @victor-wang Is that out variable a QByteArray?
                                      Also, what exactly does qDebug()<<out print out?

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

                                      @jsulm
                                      I declared it at the mainwindow.h here.

                                      This is what it got here.

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • V victor wang

                                        @jsulm
                                        I declared it at the mainwindow.h here.

                                        This is what it got here.

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

                                        @victor-wang can you do qDebug()<<out.size();?

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

                                        V 1 Reply Last reply
                                        1
                                        • jsulmJ jsulm

                                          @victor-wang can you do qDebug()<<out.size();?

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

                                          @jsulm

                                          Yes, I can do that.
                                          this is my code here

                                          And it shows 0.
                                          Is that mean there is nothing in it?

                                          JKSHJ J.HilkJ 2 Replies 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