以Qt4 的 QAbstractEventDispatcher 與 Gtk+/GNOME 元件作緊密整合
之前的 blog [
GParts - GTK+/GNOME 與 Qt/KDE 應用程式的整合] 提過包含 [
Common Main Loop] 等一系列的技術,用以解決棘手的問題:GTK+ 底層的 event loop 是建構於 GLib,而 Qt 則是一套複雜的 C++ Framework,如果要讓兩者協同運作,首先就會遇到 main loop 的議題。在這方面的進展,也促使 [
GParts] 的可能性,而我也在今年 [
KDE@Taiwan 第二次使用者聚會] 整理過去開發的心得,做了 [
淺談 KParts、XParts,以及 GParts 與桌面整合技術] (PDF slides) 的分享,事實上,在世界各地,已經有若干開發者如火如荼地展開這方面的技術突破,而 Trolltech 也在 Qt 4.1 提出 [
QAbstractEventDispatcher] API 作為回應,引用 class description 如下:
The QAbstractEventDispatcher class manages Qt's event queue, excluding GUI-related events.
It receives events from the window system and other sources. It then sends them to the QCoreApplication or QApplication instance for processing and delivery. QAbstractEventDispatcher provides fine-grained control over event delivery.
For simple control of event processing use QCoreApplication::processEvents().
For finer control of the application's event loop, call instance() and call functions on the QAbstractEventDispatcher object that is returned. If you want to use your own instance of QAbstractEventDispatcher or of a QAbstractEventDispatcher subclass, you must create your instance before you create the QApplication object.
The main event loop is started by calling QCoreApplication::exec(), and stopped by calling QCoreApplication::exit(). Local event loops can be created using QEventLoop.
Programs that perform long operations can call processEvents() with various QEventLoop::ProcessEventsFlag values OR'ed together to control which events should be delivered.
QAbstractEventDispatcher also allows the integration of an external event loop with the Qt event loop. For example, the Motif Extension included with Qt includes a reimplementation of QAbstractEventDispatcher that merges Qt and Motif events together.
於是乎,透過 Qt 4.1 的 [
QAbstractEventDispatcher] API,允許我們在 Qt Event Loop 中「調整」其 dispatcher 行為,讓其他 GUI Toolkit/widget set 得以共享 main loop 並不打擾其預期 event processing 行為。
在 2004 年初,知名 KDE 開發者 Zack Rusin 也在 KDE 開發者文件網頁寫了一篇文章 [
Integrating Qt/KDE into Gtk/GNOME apps],他設計了 QtGTK 這個輕量級的 library,證明這個概念的可行性,當然,那是 Qt3 時代的產物,相關的討論可參考 KDE.News 的新聞 [
GTK+ Apps Get Free Reign on KDE Technology], Daniel Molkentin 也延續這個發展,在以 Gtk+ 2.x 撰寫的 Beep Media Player (即 XMMS2) 中「嵌入」KDE KFileDialog,並提供兩份展示照片 [
KDE Directory Open in XMMS2] 與 [
KDE File Open in XMMS2]。而去年 Zack Rusin 加入 Trolltech 後,整個 KDE 與 FreeDesktop 也激發更多創新,[
QAbstractEventDispatcher] 一類的機制在 Qt 4.x 出現後,未來 KDE 與 GNOME 兩大桌面計畫的整合又會如何呢?咱們拭目以待 :-)
由 jserv 發表於 February 25, 2006 01:54 PM