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. Qt5 posting data to server using QUrl / QUrlQuery
Forum Updated to NodeBB v4.3 + New Features

Qt5 posting data to server using QUrl / QUrlQuery

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 12.0k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    ArtisDePartis
    wrote on last edited by
    #1

    Hi
    I have a piece of code that worked in 4.8 but now I need to port it to Qt5 (beta2)
    This is what should happen:
    I want to post some data to a webserver, the url should look like this "http://server/actions.php" Then my fields (a "Action" -string and a "data" string(json)) should be sent to the server using post. Not encoded in the url
    Here is (most) of the code:
    @QUrl params;
    // The data to post
    QVariantMap map;

    map["Title"]="The title";
    map["ProjectId"]="0";
    map["Parent"]="0";
    map["Location"]="North pole";
    map["Creator"]="You";
    map["Group"]="a group";
    QByteArray data = Json::serialize(map); //the map is converted to json im a QByteArray

    params.addEncodedQueryItem("Data",data);
    params.addQueryItem("Action", "Update");

    QNetworkRequest Request(QUrl("http://server.com/actions.php"));
    Request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    NetManager->post(Request,params.encodedQuery());@

    Now, i might not be doing this right in the first place,(It worked in 4.8) but the real problem is that addEncodedQueryItem and addQueryItem are now gone since Qt5 and I don't know what I should replace them with.
    I have read the new docs and see the new QUrlQuery but I could not figure out on my own how to use this in my case.

    1 Reply Last reply
    0
    • _ Offline
      _ Offline
      _compiler
      wrote on last edited by
      #2

      http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5

      1 Reply Last reply
      0
      • A Offline
        A Offline
        ArtisDePartis
        wrote on last edited by
        #3

        [quote author="_compiler" date="1354151723"]http://qt-project.org/wiki/Transition_from_Qt_4.x_to_Qt5[/quote]

        Thank you, but I can't see what that has to do with my question, except being a general upgrade 4>5 article.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mugunth
          wrote on last edited by
          #4

          Hi, I also have the same problem. Have you found a solution for this?

          1 Reply Last reply
          0
          • F Offline
            F Offline
            ferdna
            wrote on last edited by
            #5

            the separated the query stuff from qurl.

            QUrlQuery tmpQuery;
            tmpQuery.addQueryItem("Action", "Update");
            url.setQuery(tmpQuery);

            here:
            http://qt-project.org/doc/qt-5.0/qtcore/qurlquery.html

            1 Reply Last reply
            0

            • Login

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