Results 1 to 4 of 4

Thread: How to Terminate QtWebEngine Before Exiting

  1. #1
    Join Date
    Oct 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default How to Terminate QtWebEngine Before Exiting

    Context: It is very important for our system to be memory-leak free. We build Qt, linking to mfc to ensure a common heap is used. This allows us to work with the _CRTDBG_MAP_ALLOC/_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ) calls to detect memory leaking on exit.

    We've recently added a QtWebEngineView as a widget to our system, which brings along all the web engine processes and threads. On exit, it appears that these threads aren't shut down, and all memory resources are (erroneously?) reported as leaks. I've read through the documentation, and I'm struggling to find something to "correctly" terminate and release all web engine content prior to exit. A similar issue happens when working just with an OpenGL widget.

    Question: How does one correctly terminate and release all resources - including its OpenGL context - associated with qt web engine?

    If the motivation is insufficient, another justification would be how to release all web engine resources during program execution, in the case of limited resources?

    A simple example program:

    Qt Code:
    1. #include <QtCore>
    2. #include <QtWidgets\QMainWindow>
    3. #include <QtWebEngine\QtWebEngine>
    4. #include <QtWebEngineWidgets>
    5.  
    6. #define _CRTDBG_MAP_ALLOC
    7.  
    8. int main( int argc, char * argv[] )
    9. {
    10. _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); // enable memory leak checking
    11.  
    12. int result = 0;
    13. {
    14. QApplication app( argc, argv );
    15. QtWebEngine::initialize(); // reports leaks - likely not closed correctly on exit
    16. QMainWindow mainWindow;
    17.  
    18. QWebEngineView *webView = new QWebEngineView; // more leaks...
    19. webView->load( QUrl( "https://www.qt.io" ) ); // even more leaks...
    20.  
    21. mainWindow.setCentralWidget( webView );
    22. mainWindow.resize( 800, 600 );
    23. mainWindow.show();
    24.  
    25.  
    26. result = app.exec();
    27. }
    28. // expected Qt to have finished offloading here
    29.  
    30. return result;
    31. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: How to Terminate QtWebEngine Before Exiting

    If you look at the code for QWebEngine::initialize() you see that it registers a cleanup hook via qAddPostRoutine().
    These hooks are executes by the application object's destructor.

    If the end-of-scope destruction in main() is too late for you, then you will probably have to create the application object on the heap and delete it before main() ends.

    Cheers,
    _

  3. #3
    Join Date
    Oct 2016
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to Terminate QtWebEngine Before Exiting

    Thanks anda_skoa for the suggestion. unfortunately while it deletes the application there are still resources around. I've logged a bug: https://bugreports.qt.io/browse/QTBUG-56774 and stepping my way through the Qt code to see if there's a problem.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: How to Terminate QtWebEngine Before Exiting

    We have found that when using MFC-based DLLs in a Qt app there are extensive apparent memory leaks reported on application shutdown when running in the Visual Studio debugger. I say "apparent" because this has been reported as a known issue resulting from DLLs being unloaded in a different order than they were loaded. Here's a discussion on stackoverflow. The last comment may offer a solution.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. QupZilla is now using the QtWebEngine
    By ravas in forum Qt-based Software
    Replies: 0
    Last Post: 17th April 2016, 18:00
  2. why unable to build qtwebengine
    By swarupa in forum Newbie
    Replies: 0
    Last Post: 2nd April 2016, 20:05
  3. How to set a viewport with QtWebEngine?
    By domusmaximus in forum Qt Programming
    Replies: 0
    Last Post: 13th January 2016, 16:42
  4. QtWebEngine 5.4.2 Raspberry PI 2 not view
    By cleitonbueno in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 16th October 2015, 02:04
  5. [Qtwebengine] Running Chrome Apps in QtWebEngine
    By raunvivek in forum General Discussion
    Replies: 0
    Last Post: 9th July 2015, 14:32

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
  •  
Qt is a trademark of The Qt Company.