QObject registered to QtWebChannel cannot be accessed in javascript world synchronously when used with Qtwebengine



  • We are planning to use Qt5.7.1 and have some existing applications on qtwebkit which expect to access methods in javascript world synchronously. These are slot methods of QObject registered using addToJavaScriptWindowObject with QWebPage frame.
    When we port to Q5.7.1 these are registered to QtWebChannel object of QWebEnginePage. Now these methods are asynchronous.

    Is there any alternative for this to make these calls synchronous?

    Given that QtWebengine uses chromium and it internally spawns a different process and since these queries happens over IPC may be these are designed as async. But chromium V8 also supports synchronous IPC communication, so is it possible to support this in future if there is no way to acheive this currently?



  • Well it runs async (you cannot change that) but you can wait until it completes i.e. synchronize using synchronization primitives or e.g. using high level functionality of e.g. QFuture class like QFuture::waitForFinished()

    but remember - preferred way is to do it async i.e. connect QFuture signal to a slot
    https://stackoverflow.com/questions/25393144/blocked-qfuture-result-or-qfuturewatcher-waitforfinished

    of course you could also try other synchronization primitives like mutexes, semaphores etc.
    http://doc.qt.io/qt-5/threads-synchronizing.html

    just remember that waiting (to synchronize) may block your app/main/GUI thread for long periods of time


Log in to reply
 

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