A Taste of Qt 4

QT 季刊(中文翻譯)

來源:http://doc.trolltech.com/qq/qq09-qt4.html 【此篇文章在 QQ 網站上已被刪除,取代的是對 Qt 4.1 的介紹】

共同翻譯者:jserv

「本文是 Trolltech 官方 Qt Quarterly 的繁體中文翻譯,這不是正式的翻譯版本,但已經獲得 Trolltech 的許可」

A Taste of Qt 4─Qt 4 初體驗

With Qt 3.3.0 out the door, the Qt 3.x series is drawing closer to an end. Trolltech is now focusing on the next major release, Qt 4, to come out later this year. With Qt 4, we hope to make Qt programming faster, easier, and more powerful than it has ever been.

在 Qt 3.3.0 之後,Qt 3.x 系列的發展將告一段落。Trolltech 將會專注於下個主要版本,也就是 Qt 4,預計今年會正式推出。藉由 Qt 4,我們希望能讓 Qt 程式設計比過去來得更快速、簡單,與更具威力。

Qt is positioned as a superior alternative to Java, and as a multiplatform alternative to platform-specific APIs such as MFC and Windows Forms on Windows, Carbon on the Macintosh, or Motif on Unix. On Linux, Qt is in the unique position of being seen as one of the native APIs.

Qt 定位於更優秀的 Java 替代方案 (譯註:這裡是強調 Qt 的跨平台能力),與跨越多平台的解決方案,以取代平台相依的 API,如 Windows 上的 MFC 與 Windows Forms、Macintosh 的 Carbon,或是 Unix 上的 Motif。在 Linux 上,Qt 處於一個獨特的地位,作為一個優秀的原生 (native) API。

With Microsoft and Apple driving forward the concept of graphical user interfaces and continually refining and simplifying software development on their specific platforms, Trolltech constantly strives to improve Qt to keep abreast of these developments.

如同 Microsoft 與 Apple 在他們專屬的平台上,驅策使用者介面的效果提昇與簡化軟體發展,Trolltech 持續改進 Qt 以 "improve Qt to keep abreast of these developments" (譯註:中文翻譯抓不到感覺,所以保留原文)。

Another challenge Trolltech faces is to ensure that Qt 4 delivers more functionality than its predecessors, and has better performance: faster and with a smaller memory footprint. The performance improvements will benefit all Qt users, especially Qt/Embedded customers, many of whom prefer to use Qt 2.3 rather than Qt 3.x. The speed and size improvements will make Qt 4 well suited to Qtopia, Trolltech's palmtop environment, and will also benefit large desktop applications, most significantly on start-up performance.

另一個 Trolltech 面對的挑戰是確保 Qt 4 擁有較先前版本更多的功能與更好的效能:更快,並且有更小的記憶體使用量 (memory footprint)。所有的 Qt 使用者將會受益於 Qt 4 的效能改進,特別是 Qt/Embedded 的客戶,他們之中多數人偏好使用 Qt/Embedded 2.3.x 而非 Qt/Embedded 3.x (譯註:基於效能考量)。速度與空間的改善會使 Qt 4 更適合於 Qtopia 應用,也就是 Trolltech 的掌上型操作環境,而且,對使用大型桌上型應用程式者,也會受益於啟動的效能。(譯註:文後會提及改進程度)

Trolltech has a proven track record of bringing the Qt architecture forward without leaving the existing code base behind. Qt 4 will provide an extension library that applications based on Qt 3 can link against to use obsoleted classes. Using a separate library allows us to provide more compatibility than ever before, without bloating the Qt library with redundant functionality.

Trolltech 確保 Qt 架構的演進可讓過去既有的程式可快速升級。Qt 4 將會提供一個延伸程式庫,使得原本採用 Qt 3 的程式可以連結,以便使用在 Qt 4 中被標示汰舊 (obsoleted) 的類別。使用獨立的程式庫可讓我們提供比以往更高的相容度,而不需大幅度修改既有多餘的功能。

Here are the major highlights of the upcoming Qt 4 release.

以下列舉即將現身的 Qt 4 若干重大功能:

Seamless tools integration

更好的工具整合度


In Qt 3, Qt Designer and Qt Assistant are used independently of the programming environment. Starting with Qt 4, it will be possible to use these tools from within the programming environment. Initial plans are for integration with the Visual Studio .NET, KDevelop, and Xcode IDEs.

在 Qt 3,Qt Designer 與 Qt Assistant 在程式設計環境中,是獨立使用的。從 Qt 4 開始,這兩個工具將有更好的整合。初步的規劃是整合 Microsoft Visual Studio .NET、KDevelop (譯註:截至 KDevelop 3 為止,KDevelop 仍是將 Qt Designer 視為外部程式,而 Trolltech 的規劃則是讓 Qt Designer 與 Qt Assistant 這兩個工具可以嵌入到 KDevelop 中,這樣可以做出更佳的互動開發效果),以及 Xcode IDE。

Modern consumer-style user interfaces

新潮的使用者介面樣式


Driven by consumer electronic devices such as mobile phones and PDAs, desktop applications are moving away from standard widgets and styles towards more customized user interfaces. Qt 4 will support this modern user interface approach through its powerful style system as well as with flicker-free refreshes and transparency for all built-in and custom widgets.

受到智慧型手機與 PDA 等一類消費性電子裝置的影響,桌面應用程式越來越不拘泥於原有標準的 widget (譯註:找不到合適的中文翻譯名詞,簡單來說,我們看到的任何選單、視窗、按鈕元件都是 widget) 與樣式 (style),而是變得更加自訂化。Qt 4 將會透過 Qt 4 強大的樣式系統、低閃爍 (譯註:即 "flick-free refresh",這對液晶顯示相當重要),與透明度 (transoarency) 等設計,來支援如此新潮的使用者介面,這對所有內建與使用者自訂的 widget 都適用。

A new paint engine

新的繪圖引擎


Arthur, the new paint engine, has an innovative design that makes integrating with different pixel- and vector-based painting architectures straightforward. Quartz and QuickDraw under Mac OS X, Xlib under X11, GDI under Windows, as well as PostScript, SVG, and OpenGL, are examples of technologies that Qt 4 is expected to support---with the possibility of adding Cairo, GDI+, and PDF support later. Arthur's flexible multi-target design will make it possible to use the different paint devices' capabilities to their fullest extent---including hardware accelerated drawing operations, native transformations, and aliasing of lines and fonts. These benefits are applied automatically, making the best use of the underlying architecture.

Qt 4 會採用一個稱為 Arthur 的新繪圖引擎,讓整合若干不同像素式 (pixel) 或向量式繪圖架構變得更為直覺。Qt 4 預期會支援 Mac OS X 下的 Quartz 與 QuickDraw、X11 下的 Xlib、Windows 的 GDI,以及 PostScript、SVG,與 OpenGL,日後甚至會把 Cairo、GDI+,以及 PDF 支援納入。Authur 具有彈性的多種架構支援設計可讓不同繪圖裝置的使用上,充分發揮其效果,包含硬體加速繪圖、native transformations,與無鋸齒 (anti-alias) 的繪線與描字。這些特性將會充分發揮底層架構的威力。

A new text-rendering engine

新的文字描繪引擎


The new text engine, codenamed Scribe, offers a public API for high-quality Unicode word processing with real WYSIWYG. It has been designed from the ground up bearing multilingual challenges in mind. One of Scribe's most visible benefits, unavailable in Qt 3, is proper font kerning on all platforms.

新的文字描繪引擎,發展代號為 Scribe,提供一組開放的 API,讓高品質的 Unicode 文字處理具有真正的 WYSIWYG (譯註:"What You See Is What You Get")。Scibe 把多國語文支援列為重要的考量,與 Qt 3 相較,其中一項明顯的效益是在所有平台的 font kerning 實作。

A model/view framework

新的 Model/View framework


The new model/view framework, codenamed Interview, provides tree views, list/icon views, and tables using a common data model abstraction to support data-driven GUIs that are fast and responsive even with large data sets.

Qt 4 將採用新的 Model/View framework,發展代號為 interview,提供了 tree view、list/icon view,以及表格展現,透過一個通用性的資料抽象化模式,使得資料驅動化 (data-driven) 的 GUI 變得更加快速並且更適合大型資料需求。

qq09-interview.png

The different views can operate on the same data simultaneously. In addition, the new view classes fully support right-to-left languages.

以上三種不同的 view 可同時 (simultaneously) 處理同一份資料,而不會有資料不一致的問題。另外,新的 view 類別可完全支援從右到左書寫的語言 (譯註:如阿拉伯文、梵文)。

A new set of containers

新的 container 集


Qt 4 introduces a new set of template classes, codenamed Tulip, that are lighter, safer, and easier to use than the STL's containers. Developers who are unfamilar with the STL, or who prefer the "Qt way" of doing things, can use these new classes instead of the STL classes.

Qt 4 引進新的 template 類別集,發展代號為 Tulip,可提供比 STL 的 container (譯註:這是 ADTAbstract Data Type 的專有名詞,不翻譯) 更輕便、更安全,以及更為容易的方式。不熟悉 STL 或是偏好使用「Qt 專屬的途徑」的開發者,將會更容易上手。(譯註:但是編譯 Qt 時一樣可以指定加入 STL 支援。)

These new Qt-style classes are implicitly shared, work well in threaded environments, and are optimized for speed, low memory consumption, and minimal inline code expansion. The container classes, such as QList, QVector, QMap, QHash, and QStack, provide Java-like iterators and a powerful foreach-loop. (But unlike Java, no explicit type casting is required thanks to C++'s templates.)

這些新的 Qt 特有的類別也適合於多執行緒的環境,並且針對速度、記憶體使用量,以及最小 inline 程式展開量 (譯註:自從 Qt 2.x 開始,QTL 這個 Qt 的 STL-like 實作便捨棄 macro 的方式,改用 C++ Template 實作,但是 C++ Template 本身的實作是訴諸 code inline 的,也就是會於編譯時期展開程式碼) 等議題作了最佳化。這些 container 類別,像是 QList、QVector、QMap、QHash,以及 QStack,提供了類似 Java 的 iterator (譯註:這也是 ADT 的專有名詞,用以描述追蹤特定資料結構中儲存資料的指標,別與 C 語言的 pointer,iterator 偏抽象概念性) 與一個強大的 foreach 迴圈 (但,與 Java 不同的是,因為採用 C++ Templates,所以不需要 explicit 轉型)。(譯註:在幾個有名的 script 程式語言,像是 Perl、Python,與 PHP,都有提供 foreach 一類的關鍵字,讓程式設計員可以很便利追蹤資料。)

Qt 4 with foreach:

在 Qt 4 使用 foreach:

      foreach (QString s, list)
            sum += s.length();

Qt 4 with Java-style iterator:

在 Qt 4 使用類似 Java 的 iterator:

      QListIterator<QString> i(list);
        while (i.hasNext())
            sum += i.next().length();

Qt 4 with STL-style iterators:

在 Qt 4 使用類似的 STL 的 iterators:

      QList<QString>::const_iterator i;
        for (i = list.begin(); i != list.end(); ++i)
            sum += (*i).size();

Extensive support for multithreading

更廣泛的多執行緒支援


Qt 2 was very much a single-threaded toolkit, with some classes to abstract different platform-specific threading subsystems. During Qt 3 development, more and more functions in the library have been made reentrant to the extent that was possible. Qt 4 takes threading support to another level, with per-thread event loops, signals--slots connections across threads, and thread-safe implicit data sharing.

Qt 2 基本上是單一執行緒的 toolkit (譯註:toolkit 是 widget sets 與 library 一類「開發工具」的統稱),其中部分類別將平台相關的執行緒子系統予以抽象化。Qt 3 則將越來越多的函示儘可能重新設計,以便有 reentrant (譯註:因為譯名分歧,在此略過) 能力。Qt 4 提升多執行緒支援能力到另一個境界,可讓每個執行緒共享 event-loop (譯註:這可以解決 GUI Blocking 的問題)、跨越執行緒的 signals-slots 機制,以及可在各個執行緒間安全的分享資料。

Numerous API improvements

許多 API 改進項目


The Qt API is renowned for its its ease of use and its thorough object-oriented design. With Qt 4, we want to make it even more consistent and powerful. One way of achieving this is to reduce the number of concepts by tying the existing ones closer together. As an example, Qt 3 couples layouts and widgets relatively loosly, which can be confusing. The same is true for actions and menus items. Qt 4 brings these kinds of related classes closer together. This simplifies both Qt's implementation and its API. Another guiding principle is to continue moving from a function-based API to a more property-based API. This makes learning and using Qt easier, and it simplifies writing language bindings.

Qt API 透過物件導向設計將會更加容易使用。自 Qt 4 開始,我們想讓 Qt 程式設計能夠強健並且功能強大,為了達到這個目標,我們試著讓許多 API 之間的關係變得更緊密。例如,Qt 3 處理 layouts 與 widgets 之間的關係是相對鬆散 (譯註:"loosly coupled",這是軟體工程的術語,用以表示凝聚力低),這有時會令人誤解,同樣的現象也發生在 actions 與選單項目中。Qt 4 讓這些類別變得相對緊密,這簡化了 Qt 本身的實作與 API。另一個設計理念是繼續從原本功能導向的 API 移轉到屬性導向的 API,這讓學習與使用 Qt 變得更加簡單,同時也簡化了其他語言的連結 (language binding,譯註:泛指非 C++ 語言下使用 Qt) 撰寫功夫。

A new docking architecture

新的 docking 架構


Qt 4 will have a new and more flexible main window and docking architecture that supports modern application windows as seen on Windows and Mac OS X. Qt's current architecture follows previous style guides that treated toolbars and dock windows the same. This unification, among other things, makes predictable and meaningful docking rather difficult for an application user. The new classes support accurate visual hinting as well as tabbed docking and dock areas that dynamically slide in when needed.

Qt 4 會有一個更有彈性的新 window docking 架構,可支援在 Windows 與 Mac OS X 所見到的新潮應用程式視窗型態。Qt 目前的架構 (譯註:指的是 Qt 2.x 與 Qt 3.x) 依據之前的樣式標準,也就是視工具列與 dock 視窗為一致的。這樣的一致化處理讓原本 "predictable and meaningful docking rather difficult for an application user" (譯註:抓不到感覺,保留原文)。而新的類別支援更精準的視覺提示、多分頁 (tabbed) docking,以及可在需要時動態展現的 dock 區域。

Multiplatform accessibility

跨平台可用性 (Accessibility)


Qt 3 supports IAccessible on Windows and the Accessibility infrastructure on the Macintosh platform. A bridge has been made available by Trolltech to connect the Qt Accessibility module to Sun's Accessibility Toolkit ATK, allowing Qt 3.3 applications to integrate seamlessly with assistive technologies on Unix. Qt 4 extends this support by going beyond the rather limited world of IAccessible towards ATK's more sophisticated interfaces.

Qt 3 支援 Windows 上的 IAccessible (譯註:這是 Windows User Interface APIs 裡頭 COM 包裝的 Accessibility 介面) 與 Macintosh 平台的 Accessibility infrastructure。Trolltech 已經設計出連結 Qt Accessibility 模組到 Sun Accessibility Toolkit (ATK,譯註:在 GTK+/GNOME 2.x 已經廣泛使用),這讓 Qt 3.3 的應用程式可以無接縫的 (seamless) 整合 Unix 上對應的技術。Qt 4 進一步延伸上述的設計,"going beyond the rather limited world of IAccessible towards ATK's more sophisticated interfaces." (譯註:這句礙於譯者對 Accessibility 方面的不熟悉,所以保留原文。)

Better support for non-GUI applications

對非 GUI 應用方面更好的支援


The Qt 4 library will be split so that it will be possible to link to Qt's non-GUI functionality without linking to the GUI parts. This means that non-GUI applications such as servers and command line tools can be built using Qt's tool and container classes, event loops and timers, networking access, XML, database access, and so on, without including unwanted GUI code.

Qt 4 將會儘可能切割為兩半,一個是 GUI 相關的部分,另一個是與前者無關的非 GUI 部分,這意味著,像是伺服器一類的文字模式工具可使用 Qt 的開發工具、container 類別、event loop/timer、網路存取能力、XML、資料庫存取等等,而不需要包含與 GUI 相關的程式進來。

Significant performance and size improvements

大幅的效能與空間提升


The combined effects of many low-level improvements already in place in Qt 4 mean that applications will have executables about 10% smaller, will start up 20% faster, and will consume about 15% less memory compared to Qt 3.

許多 Qt 4 在低階實作的改進造就了相當可觀的成績,預期可使執行檔相較 Qt 3 在空間比原本小 10%、速度快 20%,以及節省 15% 的記憶體使用量。

Views
編輯   資訊
最常瀏覽頁面
 RecentChanges   12788 
 PhpWiki 測試區   5003 
 KDE@Taiwan   4345 
 RecentEdits   2858 
 KDE 心得分享區   2005 
 KDE 新聞區   1821 
 KDE 翻譯名人堂   1499 

lib/WikiDB/backend/dumb/MostPopularIter.php (In template 'html'):21: Notice: Only variables should be assigned by reference: (...repeated 364 times)

  • ?>