from PyQt5.QtCore import QUrl # create a new QUrl object url = QUrl("https://example.com/path") # set the query portion of the URL url.setQuery("key1=value1&key2=value2") print(url.toString()) # prints "https://example.com/path?key1=value1&key2=value2"
from PyQt5.QtCore import QUrl # create a new QUrl object url = QUrl() # set the URL and the query portion in the constructor url.setUrl("https://example.com/search?q=search+term") print(url.query()) # prints "q=search+term"In this example, a new QUrl object is created with the empty constructor. The setUrl() method is then used to set the entire URL, including the query portion. Finally, the query() method is called to retrieve only the query portion of the URL, which prints "q=search+term".