Web Engine/Channel communication fail using signals



  • Hi,

    I use a signal to send an object from the C++ to my web page (in the WebEngine) using the WebChannel.
    The signal is correctly triggered, however, the object is always null.
    There are no errors in the console.

    Here is the piece of code:

    index.html

    new QWebChannel(socket, function(channel) {
                            window.paymentModule = channel.objects.paymentModule;
                           
                           ...
                           
                           paymentModule.currentStatus.connect(function(status)  {
                                console.log("Status");
                                console.log(status);
                                ...
                            });
    };
    

    The class used as paymentModule in javascript:

    class WebDevice : public QObject
    {
        Q_OBJECT
    
    public:
        WebDevice(const QString &comPort, QObject *parent = 0);
    
    signals:
         void currentStatus(const Status &status);
    
    private slots:
         void onStatusUpdate(const Answer::Status &);
         ...
    };
    
    
    Q_DECLARE_METATYPE(PaymentModule::iUP250::Answer::Status)
    Q_DECLARE_METATYPE(Status)
    
    WebDevice::WebDevice(const QString &comPort, QObject *parent)
     {
    
        qRegisterMetaType<PaymentModule::iUP250::Answer::Status>();
        qRegisterMetaType<Status>("Status");
        connect(&_device, &Layer::Application::statusChanged, this, &WebDevice::onStatusUpdate, Qt::QueuedConnection); // Qt::DirectConnection
     }
    
     void WebDevice::onStatusUpdate(const Answer::Status &status)
    {
         emit currentStatus(Status());
    }
    

    All types are registered. Status class as a copy constructor, default constructor and destructor.
    It doesn't matter if Status inherit QObject or not, the result is the same.

    Sadly there isn't any error in the console. That's why I'm a bit stuck and look for help.
    Does anyone have an idea of what I could be doing wrongly ?

    Thanks,


Log in to reply
 

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