[webkit-gtk] How to load and process different URI with webkitgtk using multi-thread
Gavin Lambert
gavinl at compacsort.com
Fri Jul 13 00:08:57 PDT 2012
Quoth zzy_same:
> ThreadA: Initialize the main_window and web view; g_signal_connect
web_view
> and resource-load-finished; run gtk_main
> ThreadB(main thread): call threadA; then call
webkit_web_view_load_uri(web_view, uri)
> and wait for resource-load-finished callback function to do some
printout;
You can't do that sort of thing. UI components (including the public API of
WebKit) tend to be thread-bound, so must always be accessed from the same
thread they were created on.
For the above scenario (which is a bit weird -- usually the main thread is
the one running the GUI), you would need to call load_uri from ThreadA, and
also process the load-finished callback on that thread too. You can then
extract whatever data you need and use some thread-safe mechanism to pass
that across to your non-UI thread. (For worker thread -> UI thread
notifications you can use Glib::Dispatcher; I'm not sure if that works the
other way around though.)
More information about the webkit-gtk
mailing list