'QWebChannel after I registered some objects I need to register a new object to the Js but it faills to call this new objects cpp functions

At some I need to register some objects with qwebchannel and futher in the application I need to register a new object to the qwebchannel. The thing is that it show no error to this new object but when I try to call the c++ from this new object nothing happens.

I do something like:

Register two objects at the beggining:

this->mWebView->mViewChannel->registerObject("object1", this);
this->mWebView->mViewChannel->registerObject("object2", this);

and

registerJsObject << R"(new QWebChannel(qt.webChannelTransport, function (channel) {)";
    registerJsObject << R"window.object1 = channel.objects.object1";
    registerJsObject << R"window.object2 = channel.objects.object2";
    registerJsObject << R"(}))";
    page->runJavaScript(registerJsObject.join("\n"));

And with this in the Js side I can call all the functions from js to cpp with these objects. But at some time I need to register a new object, like:

this->mWebView->mViewChannel->registerObject("dialog", dialog);

and then I need instantiate again the others objects:

registerJsObject << R"(new QWebChannel(qt.webChannelTransport, function (channel) {)";
    registerJsObject << R"window.object1 = channel.objects.object1";
    registerJsObject << R"window.object2 = channel.objects.object2";
    registerJsObject << R"window.dialog = channel.objects.dialog";
    registerJsObject << R"(}))";
    page->runJavaScript(registerJsObject.join("\n"));

The problem is: I can use normally the old instantiated objects, but when I try to call the new object it doesn't fails but nothing happens on the Cpp side



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source