Occasionally get "QThread: Destroyed while thread is still running" when running multiple threads
-
@gunraidan said in Occasionally get "QThread: Destroyed while thread is still running" when running multiple threads:
libssl/libcrypto
It's the OpenSSL library which is needed if you want to access https URLs.
-
@jsulm said in Occasionally get "QThread: Destroyed while thread is still running" when running multiple threads:
OpenSSL library
I followed the directions here to go to this site and download the installer for Windows.
I still get the error though. :(
-
@gunraidan You should rather install OpenSSL through Qt installer/maintenance tool. See https://stackoverflow.com/questions/68624474/how-to-deploy-qt-application-with-openssl
Also, this is only an issue if you want to access HTTPS URLs. For HTTP you do not need OpenSSL.
-
I'm not sure if I should make a new thread or not, so I'll just post this here.
I can't get self.d_name to print after the api function has been called:
from PyQt6 import QtNetwork from PyQt6 import QtCore from PyQt6.QtCore import QUrl from PyQt6.QtGui import* from PyQt6 import QtWidgets from PyQt6.QtWidgets import* import sys json2qt = QtCore.QJsonDocument.fromJson class MainWindow(QWidget): def __init__ (self): super().__init__() self.title = "Window" self.left = 200 self.top = 300 self.width = 300 self.height = 300 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top,self.width, self.height) self.start_button() self.show() def start_button(self): self.s_button = QtWidgets.QPushButton(self) self.s_button.setText('Start') self.s_button.clicked.connect(self.site_request) def site_request(self): url = 'https://pokeapi.co/api/v2/pokemon/pikachu' req = QtNetwork.QNetworkRequest(QUrl(url)) self.nam = QtNetwork.QNetworkAccessManager() self.nam.finished.connect(self.handle_request) self.nam.get(req) def handle_request(self, reply): er = reply.error() if er == QtNetwork.QNetworkReply.NetworkError.NoError: qbyte = reply.readAll() pokemon_dict = json2qt(qbyte) self.d_name = pokemon_dict["abilities"][0]['ability']['name'].toString() else: print ("Error") print(reply.errorString()) def get_all(self): self.site_request() print(self.d_name) if __name__ == '__main__': app = QApplication(sys.argv) ex = MainWindow() code = app.exec() sys.exit(code)
However, when I put self.d_name to print here:
def handle_request(self, reply): er = reply.error() if er == QtNetwork.QNetworkReply.NetworkError.NoError: qbyte = reply.readAll() pokemon_dict = json2qt(qbyte) self.d_name = pokemon_dict["abilities"][0]['ability']['name'].toString() print (self.d_name) else: print ("Error") print(reply.errorString())
It prints out fine.
It should print out either way, it's a "self variable".
Anyone know what I'm doing wrong?
-
@gunraidan
It won't be aboutself
(that bit is fine), it will be about when you try to print the value.Firstly, you have
print(self.d_name)
inside a methodget_all()
. But since your code never actually callsget_all()
....Even if you did call it.
site_request()
callsself.nam.get(req)
. ButQNetworkAccessManager.get()
only initiates a GET request. It does not wait for it to complete and return. Only whenfinished
signal is received andhandle_request()
is called doesself.d_name = ...
get executed. That happens asynchronously at a later time. So trying to access it immediately after callingsite_request()
is too early.