QUrl adding parameter

  • 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("");
    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);
    //If i put this into QUrl it works fine.

    Thanks for responds

  • Qt Champions 2017

    Im not sure what question is.
    "" works then

    QString key = "29vVtpyUwORVl0aw";
    QString base="";
    QString extra="?key=";
    QUrl url( base +extra+key);

    should also work?

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

  • Qt Champions 2017

    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("" + key);
    QUrl url(QString("") + key);

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.