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



  • 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



  • The javascript is ran asynchronously ?



  • [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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.