Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. QApplication creates new thread any time

QApplication creates new thread any time

Scheduled Pinned Locked Moved Unsolved QtWebEngine
2 Posts 2 Posters 326 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zur1
    wrote on last edited by
    #1

    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,
                     **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?

    JonBJ 1 Reply Last reply
    0
    • Z zur1

      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,
                       **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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @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__).

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved