Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QUrl adding parameter

    General and Desktop
    2
    4
    1803
    Loading More Posts
    • 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
      Paysami last edited by Paysami

      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

      mrjj 1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion @Paysami last edited by

        @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 Reply Quote 2
        • P
          Paysami last edited by

          @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.

          mrjj 1 Reply Last reply Reply Quote 1
          • mrjj
            mrjj Lifetime Qt Champion @Paysami last edited by mrjj

            @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 Reply Quote 1
            • First post
              Last post