May 2019
Intermediate to advanced
542 pages
13h 37m
English
Our web posting backend will be based on a QObject simply so that we can use signals and slots.
Begin by subclassing QObject and creating a signal:
class Poster(qtc.QObject): replyReceived = qtc.pyqtSignal(str)
The replyReceived will be emitted when we receive a reply from the server to which we're posting and will carry with it the body of the reply as a string.
Now let's create the constructor:
def __init__(self): super().__init__() self.nam = qtn.QNetworkAccessManager() self.nam.finished.connect(self.on_reply)
Here, we're creating our QNetworkAccessManager object and connecting its finished signal to a local method called on_reply().
The on_reply() method will look like this:
def on_reply(self, reply): reply_bytes ...
Read now
Unlock full access