Qt6 topics merged with General

QApplication creates new thread any time

  • Hey, I'm trying to render a page few times, but unfortunately QApplication creates 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,
            self.app = QApplication(sys.argv)
            super(MainWindow, self).__init__(*args, **kwargs)
            self.browser = QWebView()
            self.networkAccessManager = QNetworkAccessManager()
            self.cookieJar = QNetworkCookieJar()
            self.__VulnCrud = VulnerabilitiesCRUD
            self.__tableName = table_name
    def ScanPage(self, pageEntity=None, forms=None, links=None, vulnUtils=None):
            self.forms = forms
            self.links = links
            self.vulnUtils = vulnUtils
            self.url = pageEntity.getURL()
            self.domain = urlparse(self.url).hostname
            curURL = QUrl(self.url)

    Any ideas how can i solve it?

  • @zur1

    • You show an __init__() method, but not what class it is init'ing. I don't know what self is.
    • I don't see anything about threads in your code.
    • You show a ScanPage() method, but not where it gets called.
    • The __init__() creates the 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 ScanPage is/where it's called from, but it's probably not the place to call QApplication.exec_() from.

    Concentrate on the error messages. You should not be calling QApplication more 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 QApplication once at the start, outside of the this, in the __main__).

Log in to reply