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 to make QNetworkAccessManager get() successfully?
Forum Updated to NodeBB v4.3 + New Features

How to make QNetworkAccessManager get() successfully?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    pachisuro4096
    wrote on last edited by
    #1

    I shared my .exe program writted by Qt on Internet.
    I want to know how many people run my program successfully, so I write a version information post on Google blog service which products a https url . I put the post url to reurl.cc service which shorts url and counts access times.

    When my program is launched, it uses QNetworkAccessManager to get() the content from the short url mentioned above.
    By this way, program can get the latest version , and I can know someone run my program successfully.

    Additionally, I also make another reurl to record my program download count.

    The result is: My program always has 1000+ download times count when I update new version of my program, but the access time always low..... download counts is 10+ times bigger than access counts.

    Even I deploy google back end script service to replace reurl service, it does not better. I concate some message to the service url and the use QNetworkAccessManager get() , send the message to the google back end script ,the script will store the message to the google sheet. This way is also not good. Only few people send the message successfully.

    I am a rookie of network program, i don't know why there has a lot of people download the program,but only very few people link successfully.......

    here is my version check code

    QNetworkAccessManager manager;
            QString url{"https://reurl.cc/XXXXXX"};
            QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
    
            QEventLoop event_loop;
            QObject::connect(reply , SIGNAL(finished()),
                             &event_loop, SLOT(quit()));
            QTimer::singleShot(10000, reply, SLOT(abort()));
            event_loop.exec();
            reply->deleteLater();
    

    here is code of sending message to google script back end

     QNetworkAccessManager manager;
            QString url{"https://script.google.com/macros/s/SCRIP_ID/exec?user="};
            QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url+QUrl::toPercentEncoding(getUserName()))));
    
            QEventLoop event_loop;
            QObject::connect(reply , SIGNAL(finished()),
                             &event_loop, SLOT(quit()));
            QTimer::singleShot(10000, reply, SLOT(abort()));
            event_loop.exec();
            reply->deleteLater();
    

    here is google script code

    function doGet(e) {
      var params = e.parameter; 
      var user = params.user; 
      var currentTime = new Date();
      
      var SpreadSheet = SpreadsheetApp.openById("GOOGLE_SHEET_ID");
      var Sheet = SpreadSheet.getSheets()[0];
      var LastRow = Sheet.getLastRow();
    
      Sheet.getRange(LastRow+1, 1).setValue(user);
      Sheet.getRange(LastRow+1, 2).setValue(currentTime);
    
      
    
      return ContentService.createTextOutput("Yesss");
      
    }
    
    jsulmJ 1 Reply Last reply
    0
    • P pachisuro4096

      I shared my .exe program writted by Qt on Internet.
      I want to know how many people run my program successfully, so I write a version information post on Google blog service which products a https url . I put the post url to reurl.cc service which shorts url and counts access times.

      When my program is launched, it uses QNetworkAccessManager to get() the content from the short url mentioned above.
      By this way, program can get the latest version , and I can know someone run my program successfully.

      Additionally, I also make another reurl to record my program download count.

      The result is: My program always has 1000+ download times count when I update new version of my program, but the access time always low..... download counts is 10+ times bigger than access counts.

      Even I deploy google back end script service to replace reurl service, it does not better. I concate some message to the service url and the use QNetworkAccessManager get() , send the message to the google back end script ,the script will store the message to the google sheet. This way is also not good. Only few people send the message successfully.

      I am a rookie of network program, i don't know why there has a lot of people download the program,but only very few people link successfully.......

      here is my version check code

      QNetworkAccessManager manager;
              QString url{"https://reurl.cc/XXXXXX"};
              QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url)));
      
              QEventLoop event_loop;
              QObject::connect(reply , SIGNAL(finished()),
                               &event_loop, SLOT(quit()));
              QTimer::singleShot(10000, reply, SLOT(abort()));
              event_loop.exec();
              reply->deleteLater();
      

      here is code of sending message to google script back end

       QNetworkAccessManager manager;
              QString url{"https://script.google.com/macros/s/SCRIP_ID/exec?user="};
              QNetworkReply *reply = manager.get(QNetworkRequest(QUrl(url+QUrl::toPercentEncoding(getUserName()))));
      
              QEventLoop event_loop;
              QObject::connect(reply , SIGNAL(finished()),
                               &event_loop, SLOT(quit()));
              QTimer::singleShot(10000, reply, SLOT(abort()));
              event_loop.exec();
              reply->deleteLater();
      

      here is google script code

      function doGet(e) {
        var params = e.parameter; 
        var user = params.user; 
        var currentTime = new Date();
        
        var SpreadSheet = SpreadsheetApp.openById("GOOGLE_SHEET_ID");
        var Sheet = SpreadSheet.getSheets()[0];
        var LastRow = Sheet.getLastRow();
      
        Sheet.getRange(LastRow+1, 1).setValue(user);
        Sheet.getRange(LastRow+1, 2).setValue(currentTime);
      
        
      
        return ContentService.createTextOutput("Yesss");
        
      }
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @pachisuro4096 said in How to make QNetworkAccessManager get() successfully?:

      here is code of sending message to google script back end

      Where is this code located?
      You are creating a local QNetworkAccessManager instance which is destroyed as soon as it gets out of scope.

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

      P 1 Reply Last reply
      1
      • jsulmJ jsulm

        @pachisuro4096 said in How to make QNetworkAccessManager get() successfully?:

        here is code of sending message to google script back end

        Where is this code located?
        You are creating a local QNetworkAccessManager instance which is destroyed as soon as it gets out of scope.

        P Offline
        P Offline
        pachisuro4096
        wrote on last edited by
        #3

        @jsulm

        I delete reply after reply has get the reply (and set timer abort() the get() if reply has wait 10sec)

        jsulmJ 1 Reply Last reply
        0
        • P pachisuro4096

          @jsulm

          I delete reply after reply has get the reply (and set timer abort() the get() if reply has wait 10sec)

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

          @pachisuro4096 Just realised: you're using a local event loop. Is there a reason why you're doing it this way?

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

          P 1 Reply Last reply
          1
          • jsulmJ jsulm

            @pachisuro4096 Just realised: you're using a local event loop. Is there a reason why you're doing it this way?

            P Offline
            P Offline
            pachisuro4096
            wrote on last edited by
            #5

            @jsulm Well......this part I just copy the internet example directory. I didn't think so much...

            jsulmJ 1 Reply Last reply
            0
            • P pachisuro4096

              @jsulm Well......this part I just copy the internet example directory. I didn't think so much...

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

              @pachisuro4096 said in How to make QNetworkAccessManager get() successfully?:

              I didn't think so much

              You should. Copying something from somewhere and hoping it will work is not the right approach. There are also examples in Qt documentation showing how to do it: https://code.qt.io/cgit/qt/qtbase.git/tree/examples/network/http?h=6.3

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

              1 Reply Last reply
              2

              • Login

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