Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. Qt 5.9.6 QWebChannel register objects after already registered others in another context
QtWS25 Last Chance

Qt 5.9.6 QWebChannel register objects after already registered others in another context

Scheduled Pinned Locked Moved Unsolved QtWebEngine
1 Posts 1 Posters 303 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rafael Silva
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved