run run chicken
run run chicken

Reputation: 503

Qt webchannel migration looks impossible with only asynchronous call from C++ API

I am working with a c++ app with HTML.

With webkit, we can call c++ API from c++ object synchronously. The logic in javascript is clear.

However with WebChannel, every API call from c++ object is asynchronous. If we get an object-B as a return value from the asyn call, then API call from object-B are also async. This not only greatly increase code complexity, but the logic is hard to maintain.

Consider this code:

new QWebChannel(qt.webChannelTransport, function (Channel) {
    var jsObject = Channel.objects.external;
    jsObject.RegisterClient("clientname", 0, function(Handle) {
        jsObject.ConfigureClient(Handle, function (clientObject) {
            clientObject.getItems(function (items) {
                for (int i = 0; i < items.size(); i++)
                {
                    items[i].calculateValue1(function (value) {
                        **// update value. Here value of 'i' will be out of over 'item.size()'.**
                        items[i].calculateValue2(function (value) {
                            // update value
                        });
                    });
                }
        });
    }); // this is asynchronous
});

First there will be too much work to migrate existing code from webkit. Second, as highlighted in bold, the for loop is broken.

Is there an alternative solution? Is there something other than webchannel that can be used in QT5.15 and above?

Upvotes: -1

Views: 178

Answers (1)

run run chicken
run run chicken

Reputation: 503

Contacted QT support, unfortunately there is no solution for this issue. All c++ API calls for webchannel are handled in another process thus impossible to be synchronous like webkit.

Upvotes: 0

Related Questions