Important: Please read the Qt Code of Conduct -

Problems with HTTP-Query

  • Hi guys,
    I'm having issues connecting to a webserver and sending a http-query. So far my code worked fine with websites that use the standard port. Additionally I now have to use a different port, now I'm having trouble to establish the connection. My Programcode looks like the following:

    QEventLoop oEventLoop;
        QNetworkAccessManager oMgr;
        QObject::connect(&oMgr, SIGNAL(finished(QNetworkReply*)), &oEventLoop, SLOT(quit()));
        QUrl oUrl(QUrl(""));
        QNetworkRequest oRequest(oUrl);
        oRequest.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
        QUrlQuery oPostData;
        QJsonDocument oJsonQuery(aParams);
        oPostData.addQueryItem("query", oJsonQuery.toJson(QJsonDocument::Compact));
        QNetworkReply* pReply =, oPostData.toString().toUtf8());
        if(pReply->error()!=QNetworkReply::NoError) {

    At first I tried using QUrl oUrl(QUrl(""));, but this one wont' work, too.

    What am I doing wrong?

  • Lifetime Qt Champion

    Can you access that URL and port via a web browser?

  • Moderators

    and what exactly isn't working?! What do you expect and what do you get?

  • @jsulm Yeah URL and port are accessible via Webbrowser or php query, just the QT-Implementation can't establish a connection.

  • Lifetime Qt Champion

    What is the output of this line:


  • @raven-worx I would expect some text as answer from the server. I do not get anything. While debugging I found out, that my program can't even connect to the Url. I'm sorry I forgot the error message:
    "Connection timed out"
    So I guessed there is anything wrong with my Code, because the URL is reachable via Webbrowser or for example php.

  • @jsulm As I said already in another answer, I'm sorry that I forgot that message:
    "Connection timed out"

Log in to reply