Results 1 to 2 of 2

Thread: Why is the lambda crashing my program?

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Why is the lambda crashing my program?

    Hi there guys, I am new to C++11 expressions. I got a lambda below and it crashes my program.
    Qt Code:
    1. void Joburg_Page::connect_to_HTML_tags(bool ok)
    2. {
    3. QString docTitle;
    4.  
    5. this->runJavaScript("document.title"
    6. "}", [&docTitle](const QVariant &data){docTitle = data.toString();});
    7.  
    8. qDebug() << docTitle <<endl;
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Why is it necessary that I must declare docTitle is a member of the class before the above code works?

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

    Default Re: Why is the lambda crashing my program?

    runJavaScript is asynchronous, the scope of connect_to_HTML_tags() has ended before the lambda is being executed.
    docTitle has ceased to exist by the time it is accessed.

    Cheers,
    _

Similar Threads

  1. Program crashing when trying to delete children window
    By umberto.palazzini in forum Qt Programming
    Replies: 1
    Last Post: 4th January 2017, 15:24
  2. CDB Debugger makes my Qt program crashing instantly
    By reezeus in forum Installation and Deployment
    Replies: 0
    Last Post: 24th September 2015, 11:17
  3. Replies: 2
    Last Post: 11th July 2013, 17:48
  4. Replies: 3
    Last Post: 27th October 2011, 12:29
  5. program crashing randomly code -1073741819
    By feraudyh in forum General Programming
    Replies: 6
    Last Post: 21st September 2010, 17:07

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.