Results 1 to 4 of 4

Thread: Closing QWebEngineView (QtWebEngineProcess.exe)

  1. #1
    Join Date
    May 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Closing QWebEngineView (QtWebEngineProcess.exe)

    So I'm trying to make a Webkit of sorts, however sometimes the pages stops to load(ideally I'd fix this problem, but can't seem to sort it out), so I've decided to come up with a hackish way of handling that issue. I want to close the current QWebEngineView then recreate it, this works as the view starts loading again, however it doesn't close itself properly. In task manager under processes i find several QtWebEngineProcess.exe processes if the program goes for a long time, which indicates that it isn't being closed properly. How if sip.delete(QWebEngineView) doesn't work what would help?
    Qt Code:
    1. def _render(url, wait):
    2. try:
    3. from PyQt5.QtCore import QEventLoop, QUrl, QTimer
    4. from PyQt5.QtWebEngineWidgets import QWebEngineView
    5. from PyQt5.QtWidgets import QApplication
    6. from sip import delete
    7.  
    8. class Render():
    9. page_load_timeout = 15
    10.  
    11. def __init__(self, url, wait):
    12. self.url = QUrl(url)
    13. self.wait = wait
    14. self.html = None
    15. self.app = QApplication(sys.argv)
    16. self._createView()
    17. while self.html is None:
    18. self.app.processEvents(
    19. QEventLoop.ExcludeUserInputEvents |
    20. QEventLoop.ExcludeSocketNotifiers |
    21. QEventLoop.WaitForMoreEvents)
    22. self.app.quit()
    23.  
    24. def _createView(self):
    25. self.view = QWebEngineView()
    26. self.view.loadFinished.connect(self._loadFinished)
    27. self.view.loadProgress.connect(self._loadProgress)
    28. self.view.load(self.url)
    29.  
    30. def _checkProgress(self):
    31. cur = time.clock()
    32. if self._lastProg + self.page_load_timeout < cur:
    33. self._lastProg = time.clock()
    34. with open(os.getcwd() + "\\files\\wk_log.txt", "a") as f:
    35. f.write("Recreating view\n")
    36. delete(self.view)
    37. self._createView()
    38.  
    39. def _loadProgress(self, prog):
    40. with open(os.getcwd() + "\\files\\wk_log.txt", "a") as f:
    41. f.write("{}\n".format(prog))
    42. if prog != 100:
    43. self._lastProg = time.clock()
    44. QTimer.singleShot((self.page_load_timeout + 0.5) * 1000, self._checkProgress)
    45.  
    46.  
    47. def _loadFinished(self, result):
    48. QTimer.singleShot(self.wait * 1000, self._timer_for_html)
    49.  
    50. def _timer_for_html(self):
    51. self.view.page().toHtml(self._callable)
    52.  
    53. def _callable(self, data):
    54. self.html = data
    55. except:
    56. print("Exception occured")
    57.  
    58. #with devnull():
    59. return Render(url, wait).html
    To copy to clipboard, switch view to plain text mode 
    Never mind the layout of the code, it's just to get my problem across. The webview will load fine a couple of times, then suddenly break. Now the current code fixes this, however it doesn't close the previous view properly. I've thought about running del self.view However I don't think that would change anything as it would just delete the reference of the view and not the actual view itself.

    Running PyQt5-5.8.2 on windows 10 64 bit, python 64 bit

  2. #2
    Join Date
    May 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Closing QWebEngineView (QtWebEngineProcess.exe)

    Seems like i found the culprite. It would seem that deleting the QWebEngineView wasn't enough, because the QWebEngineView generates a QWebEnginePage.

    I would assume that closing the view would close the page aswell, but wouldn't seem so... The fix was to get the page (or initlize as a page) and close that then the view.

    I've been running this for about 40 minutes now without any problems.

  3. #3
    Join Date
    May 2017
    Posts
    11
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Closing QWebEngineView (QtWebEngineProcess.exe)

    Scratch that, it broke, however it does seem more stable now.

  4. #4
    Join Date
    Feb 2007
    Location
    Karlsruhe, Germany
    Posts
    469
    Thanks
    17
    Thanked 90 Times in 88 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Closing QWebEngineView (QtWebEngineProcess.exe)

    Migrating from Qt5.7 to Qt5.12 and from MSVC2015 to MSVC2017 we ran into a similar situation, where QWebEngineProcess.exes would stay open after our application closed. It turned out, we did not properly specify the parent for our custom page for it to be autodeleted with the view on destruction! Hope this helps someone to avoid some debugging :-)

Similar Threads

  1. QtWebEngineProcess shared libraries
    By tkd-alex in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2016, 15:54
  2. QWebEngineView LocalStorage
    By brixel in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2016, 12:05
  3. How to know when a QWebEngineView has properly loaded?
    By domusmaximus in forum Qt Programming
    Replies: 0
    Last Post: 17th January 2016, 19:10
  4. How to set QWebEngineView on QQuickView
    By ejoshva in forum Newbie
    Replies: 112
    Last Post: 11th July 2015, 10:07
  5. Loading QDeclarativeView in QWebEngineView
    By ejoshva in forum Newbie
    Replies: 8
    Last Post: 7th May 2015, 10:38

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.