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



  • 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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.