How to make QNetworkAccessManager get() successfully?
-
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"); }
-
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"); }
@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. -
@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.I delete reply after reply has get the reply (and set timer abort() the get() if reply has wait 10sec)
-
I delete reply after reply has get the reply (and set timer abort() the get() if reply has wait 10sec)
@pachisuro4096 Just realised: you're using a local event loop. Is there a reason why you're doing it this way?
-
@pachisuro4096 Just realised: you're using a local event loop. Is there a reason why you're doing it this way?
@jsulm Well......this part I just copy the internet example directory. I didn't think so much...
-
@jsulm Well......this part I just copy the internet example directory. I didn't think so much...
@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