url = QtCore.QUrl('https://www.google.com/search?q=pyqt5') print(url.scheme()) # Prints 'https' print(url.host()) # Prints 'www.google.com' print(url.path()) # Prints '/search' print(url.query()) # Prints 'q=pyqt5'
from PyQt5.QtCore import QUrl, QUrlQuery url = QUrl() url.setScheme('https') url.setHost('www.example.com') url.setPath('/search') query = QUrlQuery() query.addQueryItem('q', 'pyqt5') query.addQueryItem('oq', 'pyqt5') url.setQuery(query.query()) print(url.toString()) # Prints 'https://www.example.com/search?q=pyqt5&oq=pyqt5'In this example, a new QUrl object is created and then built up using a series of setter methods. A QUrlQuery object is also created to manage the query string, and the addQueryItem method is used to add query parameters. Finally, the toString() method is used to get a string representation of the URL. Overall, the PyQt5.QtCore library provides a range of powerful classes for performing core functionality that is essential for any GUI application. The QUrl class is just one example of this.