user4739794
user4739794

Reputation:

Sharing (Q)WebChannel between C++ and QML

I would like to expose some C++ objects to JS. By now I have the objects correctly exposed to QML using the modifiers Q_OBJECT Q_POPERTY Q_INVOKABLE and so on. That part is working properly.

Of course, in C++ side I'm creating a WebChannel and exposing an object with something like:

QWebChannel *channel = new QWebChannel();
channel->registerObject("test", prueba);

On the other hand, I have a QML file where I'm using WebEngineView and WebChannel. I was wondering how can I connect the channel between C++ and QML.

I have seen many examples like this but I don't know how to integrate it with QML.

Any idea?

Upvotes: 0

Views: 444

Answers (1)

m7913d
m7913d

Reputation: 11064

You should not create a new (Q)WebChannel both in QML and C++. In this way, you get two different channels.

If you want to access the channel in QML, I suggest to construct a WebChannel, which is in fact a QQmlWebChannel and inherits QWebChannel.

Upvotes: 2

Related Questions