var context;// 初始化
function init(){if(typeof qt !='undefined'){newQWebChannel(qt.webChannelTransport,function(channel){
context = channel.objects.context;//name:context});}else{alert("qt对象获取失败!");}}// 向qt发送消息
function sendMessage(msg){if(typeof context =='undefined'){alert("context对象获取失败!");}else{
context.onMsg(msg);}}// 控件控制函数
function onBtnSendMsg(){
var cmd = document.getElementById("待发送消息").value;sendMessage(cmd);}init();
var g_trace_marks =[];// 接收qt发送的消息
function recvMessage(msg){alert("qt msg:"+ msg);
var lst;//以下为格式转换,分割成可用的数组
lst = msg.substring(1,msg.length-1);
lst = lst.split(",");//alert("the lst is: "+lst[0]+" "+lst[1]); if(lst[0]=="1"){//点迹
point =new BMap.Point(lst[1],lst[2]);
var marker =new BMap.Marker(point);// 创建点
map.addOverlay(marker);// 加载标注}sendMessage(msg);}