qwebchannel 多个方法报js: Uncaught TypeError: channel.execCallbacks[message.id] is not a function

这篇博客主要讨论了在使用QWebChannel进行QT与js+html交互时遇到的错误,即当大量方法同时使用时,可能出现'Uncaught TypeError: channel.execCallbacks[message.id] is not a function'的问题。作者分析认为这可能是由于QWebChannel不支持过多实例化导致的。为了解决这个问题,提出了采用全局变量和初始化方法的策略,确保只有一个QWebChannel实例,并在每个方法调用前检查和初始化。此外,还给出了具体的实现代码示例。

/*
 说明:调用qwebchannel.js 的应用js
    qwebchanneltest.js
    
*/
    $.extend({
      testexentd:function()
    {  
      new QWebChannel(qt.webChannelTransport,function(channel)
      {
          //<!--aa js调用QT Demo  -->
          var jsqtBridge =channel.objects.jsqtbridgeobj;
          window.foo=jsqtBridge;
          jsqtBridge.jscallqt();
       }});
     },
      loadXXX01Data:function()
        {
            new QWebChannel(qt.webChannelTransport,function(channel)
                {
                 jsqtBridge =channel.objects.jsqtbridgeobj;
             jsqtBridge.bdXXX01Data(function(content){
            console.log(content);
             alert(content);
            });
        },
     loadXXX02Data:function()
        {
          new QWebChannel(qt.webChannelTransport,function(channel)
                {
                 jsqtBridge =channel.objects.jsqtbridgeobj;
             jsqtBridge..bdXXX02Data(function(content){
            console.log(content);
             alert(content);
            });
              
        }
        ,
     loadXXX03Data:function()
        {
          new QWebChannel(qt.webChannelTransport,function(channel)
                {
                 jsqtBridge =channel.objects.jsqtbridgeobj;
             jsqtBridge.bdXXX03Data(function(content){
            console.log(content);
             alert(content);
            });
             
        }
......
}

在QT与js+html+ qwebchannel 进行开发时,尤其大量方法同时使用,总会莫名其妙发生如下错误,但是调用单个方法偶尔又是好的,

js: Uncaught TypeError: channel.execCallbacks[message.id] is not a function
js: Uncaught TypeError: channel.execCallbacks[message.id] is not a

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值