from PyQt5.QtCore import QUrl url = QUrl("https://www.google.com/") #creating an instance of QUrl class print(url.scheme()) #output: 'https' print(url.host()) #output: 'www.google.com'
from PyQt5.QtCore import QUrl url = QUrl() url.setScheme("http") url.setUserName("myuser") url.setPassword("mypassword") url.setHost("www.example.com") url.setPath("/path/to/file") url.addQueryItem("key1", "value1") url.addQueryItem("key2", "value2") print(url.toString()) #output: 'http://myuser:[email protected]/path/to/file?key1=value1&key2=value2'In this example, we use QUrl to build a URL by setting the various components (scheme, username, password, host, path, and query string) using the relevant methods. We then use the `toString()` method to get the final URL as a string. Overall, QUrl is a useful class for manipulating URLs in PyQt applications.