문제

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. token is not a valid query item in your given URL. For https://www.example.com/success.html?token=XYZ&user=guest it 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 # with QUrl::fragment().

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top