I have a QUrl as this: https://www.example.com/success.html#token=XYZ&user=guest and I want to obtain the value of the token i.e. XYZ
My current code
QString token = url.queryItemValue(QString("token"));
cout << QString("access token is %1").arg(access_token);
returns an empty string.
Of course it returns an empty string.
tokenis not a valid query item in your given URL. Forhttps://www.example.com/success.html?token=XYZ&user=guestit would be valid. Usually#is used for an anchor name reference and not for parameters. If you really have URLs like that, you need to either first convert the#into a?or custom parse the URL. You can get the stuff followed by the#withQUrl::fragment().