Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[SOLVED]QNetworkReply problem



  • I am sending a QNetworkRequest to a website.Here is the code :
    @QNetworkRequest request;
    request.setUrl(QUrl( "http://www.twmentor.com/?tool=attack"));
    request.setRawHeader( "User-Agent", m_userAgent.toLatin1() );
    request.setHeader( QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded" );
    QUrl params;
    params.addEncodedQueryItem( "sendTime-hour:", QUrl::toPercentEncoding("hh"));
    params.addEncodedQueryItem( "sendTime-min", QUrl::toPercentEncoding("mm" ) );
    params.addEncodedQueryItem( "sendTime-sec", QUrl::toPercentEncoding( "ss" ) );
    params.addEncodedQueryItem( "sendTime-day", QUrl::toPercentEncoding("dd"));
    params.addEncodedQueryItem( "sendTime-mon", QUrl::toPercentEncoding("mm" ) );
    params.addEncodedQueryItem( "sendTime-year", QUrl::toPercentEncoding( "yy" ) );
    params.addEncodedQueryItem( "stopTime-hour", QUrl::toPercentEncoding("hh"));
    params.addEncodedQueryItem( "stopTime-min", QUrl::toPercentEncoding("mm" ) );
    params.addEncodedQueryItem( "stopTime-sec", QUrl::toPercentEncoding("ss" ) );
    params.addEncodedQueryItem( "stopTime-day", QUrl::toPercentEncoding( "dd" ) );
    params.addEncodedQueryItem( "stopTime-mon", QUrl::toPercentEncoding("mm"));
    params.addEncodedQueryItem( "stopTime-year", QUrl::toPercentEncoding("yy" ) );
    params.addEncodedQueryItem( "landTime-hour", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->time().hour()).toLatin1() ));

    params.addEncodedQueryItem( "landTime-min", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->time().minute()).toLatin1() ));
    params.addEncodedQueryItem( "landTime-sec", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->time().second()).toLatin1() ) );
    params.addEncodedQueryItem( "landTime-day", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->date().day()).toLatin1() ) );
    params.addEncodedQueryItem( "landTime-mon", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->date().month()).toLatin1() ) );
    params.addEncodedQueryItem( "landTime-year", QUrl::toPercentEncoding( QString(this->dateTimeEditAtackLanding->date().year()).toLatin1() ) );
    params.addEncodedQueryItem( "uz", QUrl::toPercentEncoding("Europe/Bucharest" ) );
    params.addEncodedQueryItem( "tz", QUrl::toPercentEncoding("Europe/Bucharest" ) );
    params.addEncodedQueryItem( "worldSpeed", QUrl::toPercentEncoding("1" ) );
    params.addEncodedQueryItem( "troopSpeed", QUrl::toPercentEncoding("1" ) );
    params.addEncodedQueryItem( "perTarget", QUrl::toPercentEncoding(this->lineEditAtackPerVillage->text().toLatin1() ) );
    params.addEncodedQueryItem( "troopPerSq", QUrl::toPercentEncoding("35" ) );
    params.addEncodedQueryItem( "sourceVills", QUrl::toPercentEncoding(this->plainTextEditYourVillages->toPlainText().toLatin1() ) );
    params.addEncodedQueryItem( "targetVills", QUrl::toPercentEncoding(this->plainTextEditEnemyVillages->toPlainText().toLatin1() ) );
    params.addEncodedQueryItem( "hiddenCheck", QUrl::toPercentEncoding("1" ) );
    params.addEncodedQueryItem( "submit", QUrl::toPercentEncoding("Plan attack" ) );
    QByteArray paramBytes = params.toString().mid( 1 ).toLatin1();
    paramBytes.replace( "/", "/" );
    QNetworkReply reply=m_nam->post(request,paramBytes);
    connect( reply, SIGNAL( finished() ),
    SLOT(replyTwMentor()));@
    But if "plainTextEditYourVillages" and "plainTextEditEnemyVillages" contains more information the html code replyed by the website contains also more html code.And when i use the following code :
    @QNetworkReply
    reply = qobject_cast<QNetworkReply*>( sender() );
    QByteArray info2 =reply->readAll();
    qDebug()<<info2;@

    info2 is empty.What is the problem?Does the reply contains too much html code or I've send to much information and it wasn't received by the website?If I put less data I get the html code in the variable info2.
    Another problem is that all calls to dateTimeEditAtackLanding->time().minute()).toLatin1() return nothing.



  • After some test i see that the html code is too long.What can I do about this?



  • To those who will have the same problem...you need to use the readyRead() signal.Thanks to peppe(mirc) for the help.


Log in to reply