QWebChannel pass QObject from JS



  • Hello,

    is it possible with a webchannel to pass objects (QObject derived) in js?

    To explain it, i habe something like this:
    c++

    class B;
    class A : public QObject
    {
        Q_OBJECT
        public slots:
            void pass_b(const B *b) {...}                     // do something with b
    }
    
    class B : public QObject
    {
        Q_OBJECT
    }
    

    js

    function someFunc()
    {
        var b = {};                                  // ignore how I got a b-object here ;)
        channel.objects.a.pass_b(b);
    }
    

    As I see, a Json-object will be delivered. But when it comes to argument interpretation (QMetaObjectPublisher::invokeMethod) the json-object is passed to a QVariant and is checked if the needed parameter for the called method is QVariant or if the QVariant-object can be converted to the needed type. But a json-object can not be converted to a QObject. There is no check with wrappedObjects if the object is already known.

    PS: I used the qtwebchannel module from the qt5 github repo in dev-branch.


Log in to reply
 

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