QApplication creates new thread any time
zur1 last edited by
Hey, I'm trying to render a page few times, but unfortunately
QApplicationcreates a new thread every time and when i'm trying to run the rendering on the second time it's saying:
QApplication was not created in the main() thread.In addition i am getting the following error:
QApplication::exec must be called on main thread
I tried to create Qapplication object only once, but the trigger for the render method is an event recieved from socketIO module.
At the first time the render does works. At the second time the render crash the whole application
Here is a snipped code:
def __init__(self, table_name=None, db_type=None, *args, **kwargs): self.app = QApplication(sys.argv) self.app.setApplicationName(QString("Chrome")) self.app.setApplicationVersion(QString("53.0.2785.113")) super(MainWindow, self).__init__(*args, **kwargs) self.setWindowTitle("ScarpSite") self.browser = QWebView() self.networkAccessManager = QNetworkAccessManager() self.cookieJar = QNetworkCookieJar() self.__VulnCrud = VulnerabilitiesCRUD self.__tableName = table_name self.get_configuration_properties() def ScanPage(self, pageEntity=None, forms=None, links=None, vulnUtils=None): self.forms = forms self.links = links self.vulnUtils = vulnUtils self.updateCookiesMechanizetoQt(self.vulnUtils.getCookieJar()) self.url = pageEntity.getURL() self.domain = urlparse(self.url).hostname self.browser.loadFinished.connect(self.__onUrlLoaded) self.browser.page().setNetworkAccessManager(self.networkAccessManager) self.browser.page().userAgentForUrl(QUrl(self.url)) curURL = QUrl(self.url) self.browser.load(curURL) self.setCentralWidget(self.browser) self.show() self.app.exec_()
Any ideas how can i solve it?
JonB last edited by JonB
- You show an
__init__()method, but not what class it is init'ing. I don't know what
- I don't see anything about threads in your code.
- You show a
ScanPage()method, but not where it gets called.
QApplication. As I said I don't know what it is init'ing, but that's probably not the place to create the application.
- I don't know what
ScanPageis/where it's called from, but it's probably not the place to call
Concentrate on the error messages. You should not be calling
QApplicationmore than once. You must create it from the
main()thread (the bit where you test for
if__name__== "__main__"). Same for the call to
exec_(). Whatever you mean about "but the trigger for the render method is an event recieved from socketIO module" needs sorting out to obey this (e.g. some sort of you only create the
QApplicationonce at the start, outside of the this, in the
- You show an