Undefined properties and return types when using QWebChannel

后端 未结 2 2003
花落未央
花落未央 2020-12-30 13:20

Based on QT QWebEnginePage::setWebChannel() transport object and Qt: Cannot invoke shared object methods/properties from javascript I tried to make a small demo to test the

2条回答
  •  时光取名叫无心
    2020-12-30 13:51

    Faced same issue... Reading doc's carefully gave me the answer. The answer is that communication between Qt and JS in Qt5 is asynchronous. You have to provide callback function which will be called after method completed and result value received.

    Instead of calling

    var n = theQtObj.getInt(X);
    PrintLog("  back in js with n="+n);
    

    you can call at as

    theQtObj.getInt(X, function(n) {
        PrintLog(" back in js with n="+n);
    });
    

提交回复
热议问题