#includeint main(int argc, char *argv[]) { QUrl url("https://example.com/path/to/resource.html?param=value"); qDebug() << "Scheme: " << url.scheme(); // Output: Scheme: https qDebug() << "Host: " << url.host(); // Output: Host: example.com qDebug() << "Path: " << url.path(); // Output: Path: /path/to/resource.html qDebug() << "Query: " << url.query(); // Output: Query: param=value // Build a new URL from its components QUrl newUrl; newUrl.setScheme("ftp"); newUrl.setHost("ftp.example.com"); newUrl.setPath("/path/to/file.txt"); newUrl.setUserName("username"); newUrl.setPassword("password"); qDebug() << "New URL: " << newUrl.toString(); // Output: New URL: ftp://username:[email protected]/path/to/file.txt return 0; }
#includeThis example demonstrates how to use QUrl to add a query parameter to an existing URL using the addQueryItem() method. Package library: QtNetworkint main(int argc, char *argv[]) { QUrl url("https://example.com/path/to/resource.html"); // Add a query parameter to the URL url.addQueryItem("param", "value"); qDebug() << "New URL: " << url.toString(); // Output: New URL: https://example.com/path/to/resource.html?param=value return 0; }