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. How to manage the lifecycle of a lambda function in QWebEnginePage::runJavaScript method
Forum Update on Monday, May 27th 2025

How to manage the lifecycle of a lambda function in QWebEnginePage::runJavaScript method

Scheduled Pinned Locked Moved Unsolved QtWebEngine
1 Posts 1 Posters 431 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.
  • M Offline
    M Offline
    mahdikhani
    wrote on last edited by
    #1
    
       QWebEngineView webEngineView;
       //...
       webEngineView->page()->runJavaScript("...", [this](const QVariant &v)
       {
          this->f();
       });
    
    

    The problem is that sometimes 'this' is destructed when the lambda function is called. Suppose 'this' is derived from QObject, how can we ensure that 'this' is valid when the lambda function is called? For example when using QObject::connect when we specify a context for lambd function, and when the destination object is destroyed the connection is disconnected automatically.

    1 Reply Last reply
    0

    • Login

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