[PyQt] QWebEnginePage API for callbacks
kovid at kovidgoyal.net
Tue Jan 6 06:26:11 GMT 2015
There is no direct way to convert an asynchronous API into a synchronous
Here is a hackish way to do it.
text = None
text = x
while text is None:
QApplication.instance().processEvents(QEventLoop.ExcludeUserInputEvents | QEventLoop.ExcludeSocketNotifiers | QEventLoop.WaitForMoreEvents)
# now save the text
This is the simplest (somewhat robust) way to simulate the old blocking
behavior of toPlainText(). There are some problems with this
Spinning the event loop means that other parts of your code might be
called, for instance in response to timer events, or events from the OS.
With the old synchronous API that could not happen.
However, for most use cases it will work fine.
What is really needed is for Qt to provide a synchronous wrapper around
the API that avoids these problems. In other words a flag to
processEvents that causes it to only deliver webkit related events and
hold everything else. That would make porting to
QWebEngine somewhat easier.
On Mon, Jan 05, 2015 at 02:06:25PM -0800, David Cortesi wrote:
> In Qt5.4, the new QWebEngine interface takes account of the fact that the
> underlying Chromium engine is asynchronous. Four of the methods of
> QWebEnginePage take an argument "FunctorOrLambda" as a callback to receive
> control when the result is ready (for example, ).
> Using PyQt, I assume we can pass a Python defined function or lambda in
> this position?
> I'm a bit at a loss what to do following a call to such a method. What is
> the best way to "idle" until the callback comes? n.b. I don't see any
> WebEngine specific guidance at the PyQt5 doc .
> Thanks for any suggestions,
> Dave Cortesi
>  http://doc.qt.io/qt-5/qwebenginepage.html#toPlainText
>  http://pyqt.sourceforge.net/Docs/PyQt5/pyqt4_differences.html
> PyQt mailing list PyQt at riverbankcomputing.com
Dr. Kovid Goyal
More information about the PyQt