Basically, I have 4 widgets in a QStackedWidget which are:
In ProcessWidget and LoadingWidget I will use QNetworkAccessManager to communicate with my API.
The flow of my application:
Begin with HomeWidget.
Then, switch to ProcessWidget.
Then, switch to ConfirmWidget.
Then, switch to LoadingWidget.
Then, switch back to HomeWidget and so on.
In ProcessWidget I only make 1 request. But in LoadingWidget I have 4 requests.
This is how I make the communication for each request (the difference of each request is the URL only):
def doRequest(self):
url = "http://127.0.0.1:8000/api"
req = QtNetwork.QNetworkRequest(QUrl(url))
self.networkAccessManager = QtNetwork.QNetworkAccessManager()
self.networkAccessManager.finished.connect(self.handleResponse)
self.networkAccessManager.get(req)
def handleResponse(self, reply):
er = reply.error()
if er == QtNetwork.QNetworkReply.NoError:
bytes_string = reply.readAll()
data = json.loads(str(bytes_string, 'utf-8'))
# Do something
else:
errorMessage = "Error occured: "+ str(er) + "\n"+ str(reply.errorString())
# Do something
The problem is, on the 4th iteration of the flow process of my application, suddenly my application crash. It gives this error:
Process Finished With Exit Code 139 (Interrupted by signal 11: SIGSEGV)
What is the mistake?
Finally, I can solve the problem by redefining how I make the request.
This is the code:
# Instantiate the NetworkAccessManager as the Widget's property
self.networkAccessManager = QtNetwork.QNetworkAccessManager()
def doRequest(self):
url = "http://127.0.0.1:8000/api"
req = QtNetwork.QNetworkRequest(QUrl(url))
reply = self.networkAccessManager.get(req)
reply.finished.connect(self.handleResponse)
def handleResponse(self):
reply = self.sender()
er = reply.error()
if er == QtNetwork.QNetworkReply.NoError:
bytes_string = reply.readAll()
data = json.loads(str(bytes_string, 'utf-8'))
# Do something
else:
errorMessage = "Error occured: "+ str(er) + "\n"+ str(reply.errorString())
# Do something
reply.deleteLater()
I can conclude that the problem come from the reply object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.