[Interest] QNetwork classes for submitting google forms

Max Paperno max-l at wdg.us
Sat Jun 12 02:29:42 CEST 2021


Ah yeah, it would help a lot to have a Qt event loop to actually deliver 
the signals... silly me. Also forgot to delete the reply as per docs.

Tested, works:

----------------
int main(int argc, char**argv)
{
   QCoreApplication app(argc, argv);
   QUrlQuery postData;
   postData.addQueryItem("entry.2020959411", "Qt Query");

   QUrl serviceUrl("http://httpbin.org/post");
   QNetworkRequest request(serviceUrl);
   QNetworkAccessManager networkManager;

   QObject::connect(&networkManager, &QNetworkAccessManager::finished,
                    [&](QNetworkReply *reply) {
       int status = 
reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
       qDebug() << "Got status:" << status << "Data:" << reply->readAll();
       //  etc....
       reply->deleteLater();
       app.exit();
   });

   networkManager.post(request,
postData.toString(QUrl::FullyEncoded).toUtf8());

   return app.exec();
}
------------


Please reply to the list, not to me, thanks.

HTH,
-Max


On 6/11/2021 6:53 PM, Nicholas Yue wrote:
> ```
> intmain()
> {
> QUrlQuerypostData;
> postData.addQueryItem("emailAddress","abc.xyz at gmail.com <mailto:abc.xyz at gmail.com>");
> postData.addQueryItem("entry.2020959411","QtQuery");
> QUrlserviceUrl("https://docs.google.com/forms/d/152CTd4VY9pRvLfeACOf6SmmtFAp1CL750Sx72Rh6HJ8/formResponse");
> QNetworkRequestrequest(serviceUrl);
> QNetworkAccessManagernetworkManager;
> boolgotResponse=false;
> QObject::connect(&networkManager,&QNetworkAccessManager::finished,
> [&gotResponse](QNetworkReply*reply){
> intstatus=reply->attribute(
> QNetworkRequest::HttpStatusCodeAttribute).toInt();
> qDebug()<<status;
> //etc....
> gotResponse=true;
> });
> networkManager.post(request,
> postData.toString(QUrl::FullyEncoded).toUtf8());
> while(!gotResponse){
> QThread::sleep(1);//orwhateversleepmethod,justwaitingforaresponse.
> qDebug()<<"Slept1second";
> }
> return0;
> }
> ```
> It just sits there, I get the regular print out about 'Slept 1 second', other than that, it does not seems to be working
>
> On Fri, 11 Jun 2021 at 14:18, Max Paperno <max-l at wdg.us 
> <mailto:max-l at wdg.us>> wrote:
>
>
>     > QObject::connect(&networkManager, &networkManager::finished, ...
>
>     Whoops, should really be
>     QObject::connect(&networkManager,
>     &QNetworkAccessManager::finished, ...
>
>     -Max
>     _______________________________________________
>     Interest mailing list
>     Interest at qt-project.org <mailto:Interest at qt-project.org>
>     https://lists.qt-project.org/listinfo/interest
>
>
>
> -- 
> Nicholas Yue
> Graphics - Arnold, Alembic, RenderMan, OpenGL, HDF5
> Custom Dev - C++ porting, OSX, Linux, Windows
> http://au.linkedin.com/in/nicholasyue
> https://vimeo.com/channels/naiadtools




More information about the Interest mailing list