Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [solved] C++11 functor not changing variable declared outside

[solved] C++11 functor not changing variable declared outside

Scheduled Pinned Locked Moved C++ Gurus
3 Posts 2 Posters 1.1k 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.
  • N Offline
    N Offline
    nando76
    wrote on last edited by
    #1

    Hi,
    i try to assign a value to a variable inside a functor.
    Inside the functor the value seems ok, but outside the value is not changed, any ideas?

    My code looks like this:
    @
    double lat = 0.0;
    double lon = 0.0;

    m_webView->page()->runJavaScript("document.documentElement.contentEditable = true");
    
    m_webView->page()->runJavaScript("document.getElementById(\"markerLat\").value",
                                     [&](const QVariant &result)
    {
        lat = result.toDouble();
        qDebug() << " lat in functor=" &lt;&lt; lat;  // HERE lat IS OK! 
    }
    );
    
    // HERE LAT IS NOT SET, BUT WHY?
    qDebug() &lt;&lt; " lat outside functor=" << lat;
    

    @

    Greetings
    Nando

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sandy.martel
      wrote on last edited by
      #2

      The javascript is ran asynchronously ?

      1 Reply Last reply
      0
      • N Offline
        N Offline
        nando76
        wrote on last edited by
        #3

        [quote author="sandy.martel" date="1415634139"]The javascript is ran asynchronously ?[/quote]

        Thank you! That was excactly the problem
        I made the variables (lat and lon) member of my class and now it works perfectly.

        Greetings
        Nando

        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