从JavaScript调用C ++函数

时间:2017-02-24 19:09:34

标签: javascript c++ qt

我尝试使用QWebEngineViewQWebChannel与JavaScript文件关联起来 这是我的HTML文件(qmapview中声明的mapapi.js):

<script type="text/javascript" src="src/mapapi.js"></script>
<script type="text/javascript">

//<![CDATA[

function load()
{
    if (typeof qt !== 'undefined')
    new QWebChannel(qt.webChannelTransport, function(channel) {
        qmapview = channel.objects.qmapview;
        if (qmapview.isEarthAvailable()) {
            google.load("earth", "1", {"language": "en", "other_params":"sensor=false"});
        }
    } );

    showDiv(document.getElementById("map"));
    hideDiv(document.getElementById("earth"));

    mapi.init(document.getElementById("map"));
    mapi.panorama.init();

    traffic.init();
    directions.init();
}

//]]>
</script>

  

这是对象的注册

 m_webChannel = new QWebChannel();
    m_webpage->setWebChannel(m_webChannel);
    m_webChannel->registerObject("qmapview", this) ;

我想从js文件中调用object的函数(类似于qmapview.mapZoomChanged();)之类的东西,但现在不要在我的情况下这样做。

我读过有关Q_Property的内容,但不明白。

在调试这样的事情:

Property 'visible'' of object 'MapWidget' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'minimized'' of object 'MapWidget' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'maximized'' of object 'MapWidget' has no notify signal and is not constant, value updates in HTML will be broken!
Property 'fullScreen'' of object 'MapWidget' has no notify signal and is not constant, value updates in HTML will be broken!

0 个答案:

没有答案