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. QWebChannel: Invoking C++ methods from Js, with complex arguments
Forum Update on Monday, May 27th 2025

QWebChannel: Invoking C++ methods from Js, with complex arguments

Scheduled Pinned Locked Moved QtWebEngine
1 Posts 1 Posters 1.7k 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.
  • D Offline
    D Offline
    daniele
    wrote on last edited by
    #1

    Hi,
    I've set up a qwebchannel client/server application the same way as it's done in the "standalone" example: https://github.com/qtproject/qtwebchannel/tree/dev/examples/webchannel/standalone

    I can successfully invoke C++ methods from JavaScript, but I can't find a way to pass complex arguments like arrays or objects.

    To be more specific, this is my personal C++ method:
    @void receiveMessage(QString msg, QVariant data);@

    And these are some calls from JavaScript
    @registeredObject.receiveMessage("HELLO", "something") // Works
    registeredObject.receiveMessage("HELLO", 45) // Works
    registeredObject.receiveMessage("HELLO", [45]) // DOESN'T work
    registeredObject.receiveMessage("HELLO", {some: "thing"}) // DOESN'T work@

    With "doesn't work" I mean that the application crashes. When I'm within the receiveMessage() method, the debugger says that the "data" argument is not accessible.

    I suspect (but it's only a suspect) that the problem lies somewhere here: https://github.com/qtproject/qtwebchannel/blob/dev/src/webchannel/qmetaobjectpublisher.cpp#L361

    What can I do to fix it? Am I doing it wrong?
    Thanks

    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