QUrl url("https://example.com/page.html#header"); url.setFragment("footer"); QString newUrl = url.toString(); // "https://example.com/page.html#footer"
QUrl url("https://example.com/page.html#section1"); url.setFragment(""); QString newUrl = url.toString(); // "https://example.com/page.html"In this example, the original URL had a fragment of "section1". The setFragment method was used with an empty string argument to clear the fragment from the URL. Package library: Qt Core library.