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. QUrl adding parameter

QUrl adding parameter

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 2.4k Views
  • 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.
  • P Offline
    P Offline
    Paysami
    wrote on 8 Mar 2017, 18:38 last edited by Paysami 3 Aug 2017, 18:59
    #1

    Hello there,
    After 2hours of trying add variable into QUrl i decided to write for help.
    I need to put parameter and value after base url.
    Key is in private like QString key;

    QString key = "29vVtpyUwORVl0aw";
    QUrl url("http://127.0.0.1/restapi/api.php");
    QNetworkRequest request(url);
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
    //reply and responses
    

    This is what i want to prepare for QNetworkRequest request(url);

    http://127.0.0.1/restapi/api.php?key=29vVtpyUwORVl0aw
    //If i put this into QUrl it works fine.
    

    Thanks for responds

    M 1 Reply Last reply 8 Mar 2017, 20:03
    0
    • P Paysami
      8 Mar 2017, 18:38

      Hello there,
      After 2hours of trying add variable into QUrl i decided to write for help.
      I need to put parameter and value after base url.
      Key is in private like QString key;

      QString key = "29vVtpyUwORVl0aw";
      QUrl url("http://127.0.0.1/restapi/api.php");
      QNetworkRequest request(url);
      request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
      //reply and responses
      

      This is what i want to prepare for QNetworkRequest request(url);

      http://127.0.0.1/restapi/api.php?key=29vVtpyUwORVl0aw
      //If i put this into QUrl it works fine.
      

      Thanks for responds

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 8 Mar 2017, 20:03 last edited by
      #2

      @Paysami
      Hi
      Im not sure what question is.
      If
      "http://127.0.0.1/restapi/api.php?key=29vVtpyUwORVl0aw" works then

      QString key = "29vVtpyUwORVl0aw";
      QString base="http://127.0.0.1/restapi/api.php";
      QString extra="?key=";
      QUrl url( base +extra+key);

      should also work?

      1 Reply Last reply
      2
      • P Offline
        P Offline
        Paysami
        wrote on 8 Mar 2017, 20:43 last edited by
        #3

        @mrjj
        Thanks for respond.
        lol, its working.

        I tried that for first but it was not working.
        I was reading full manual of QNetworkRequest about some headers, atributes and etc..
        Maybe i had some bad syntaxes because QUrl wasnt allow something next then "string".

        Thanks for help.

        M 1 Reply Last reply 8 Mar 2017, 21:13
        1
        • P Paysami
          8 Mar 2017, 20:43

          @mrjj
          Thanks for respond.
          lol, its working.

          I tried that for first but it was not working.
          I was reading full manual of QNetworkRequest about some headers, atributes and etc..
          Maybe i had some bad syntaxes because QUrl wasnt allow something next then "string".

          Thanks for help.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 8 Mar 2017, 21:13 last edited by mrjj 3 Aug 2017, 21:13
          #4

          @Paysami
          Super :)
          Good work reading the docs.
          Well, one trap i sometimes fall in is
          QString + QString + char *
          Where it really wants
          QString + QString + QString(char *)
          So as example
          QUrl url("http://127.0.0.1/restapi/api.php" + key);
          --->
          QUrl url(QString("http://127.0.0.1/restapi/api.php") + key);

          I am only guessing. The error could have been many things. :)

          1 Reply Last reply
          1

          1/4

          8 Mar 2017, 18:38

          • Login

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