1. 全新的Qt5Qt5帶來的全新功能,模塊和開發模型,將使Qt擁有更美好的未來殷允嶠 Charles Yin developer @ QML Core Team
[email protected] 2. 自我介紹/About me• 殷允嶠 (Charles Yin)• 現居住在澳大利亞昆士蘭州的布里斯班• 2009年加入Qt Brisbane R&D lab• 曾經參與的項目 1. 短暫維護QtSql模塊 2. Qt Mobility項目中QtContacts, QtOrganizer, QtVersit和QtFeedback的研發 3. 2010年加入QML Core team, 主要負責QtQuickTest研發和維護, Canvas組件的設計和實現,QtQuick2 Animation部分的重寫,並參與部分性能調整的工作• 聯絡我: gmail/gtalk/facebook
[email protected], twitter:yinyunqiao, linkedin: yinyunqiao, IRC@freenode: chayin 3. Qt5新開發模型:模塊化git代碼倉庫git://gitorious.org/qt/qlalr.git git://gitorious.org/qt/qt3support.git https://codereview.qt-project.org/#admin,projects git://gitorious.org/qt/qtactiveqt.git git://gitorious.org/qt/qtbase.git http://qt.gitorious.org/git://gitorious.org/qt/qtdeclarative.git git://gitorious.org/qt/qtdoc.git git://gitorious.org/qt/qtmultimedia.git$ git clone git://gitorious.org/qt/qt5.git git://gitorious.org/qt/qtphonon.git$ ./init-repositorygit://gitorious.org/qt/qtqa.git git://gitorious.org/qt/qtrepotools.git git://gitorious.org/qt/qtscript.git git://gitorious.org/qt/qtsvg.git git://gitorious.org/qt/qttools.git git://gitorious.org/qt/qttranslations.git git://gitorious.org/webkit/qtwebkit.git git://gitorious.org/qt/qtwebkit-examples-and-demos.git git://gitorious.org/qt/qtxmlpatterns.git … 4. Qt5基本模塊 / Qt5 Essentials Modules QtWebkit QtMultiMediaQtTest QtSql QtQmlQtQuick QtNetwork QtGuiQtCore 5. QtCore: 全新的信號-槽(Signal-Slot)語法先來溫習一下傳統的信號/槽語法:connect(sender, SIGNAL(valueChanged(QString,QString)),receiver, SLOT(updateValue(QString)) ); 6. QtCore: 全新的信號-槽(Signal-Slot)語法connect(sender, SIGNAL(valueChanged(QString,QString)),receiver, SLOT(updateValue(QString)) );問題:• 缺少編譯期語法檢查: 宏 + 字符串• 對C++類型系統不友好: typedef, namespace, etc.• 潛在的性能損失: 運行時解析字符串 7. QtCore: 全新的信號-槽(Signal-Slot)語法connect(sender, SIGNAL(valueChanged(QString,QString)),receiver, SLOT(updateValue(QString)) );connect(sender, &Sender::valueChanged,receiver, &Receiver::updateValue ); 8. QtCore: 全新的信號-槽(Signal-Slot)語法connect(sender, &Sender::valueChanged,receiver, &Receiver::updateValue ); • 更符合現代C++語法It’s nicernow!The pervasive use of macros in C is probably themajor reason we didnt have excellent C++development environments a decade ago. -Bjarne Stroustrup 9. QtCore: 全新的信號-槽(Signal-Slot)語法 connect(sender, &Sender::valueChanged, receiver, &Receiver::updateValue );• 編譯期檢查: C++類成員函數指針, 錯誤的信號/槽鏈接將產生編譯期錯誤而不是運行時警告 • 拼寫錯誤 • 類型不匹配 • 代碼重構 • 將可以更多使用 static_assert: 比如當缺少Q_OBJECT時 10. QtCore: 全新的信號-槽(Signal-Slot)語法connect(sender, &Sender::valueChanged,receiver, &Receiver::updateValue );• 參數類型自動轉換 class Test : public QObject { Q_OBJECT public: Test() { connect(this, &Test::someSignal, this, &Test::someSlot); }signals: void someSignal(const QString &); public:void someSlot(const QVariant &); }; 11. QtCore: 全新的信號-槽(Signal-Slot)語法connect(sender, &Sender::valueChanged,receiver, &Receiver::updateValue );• 任何函數都可成為槽函數, slot 關鍵字, Q_SLOTS宏都將成為過去 static void someFunction() { qDebug() selectedFiles().first()); // ... save document here ... }dlg->deleteLater();}); 13. QtCore: C++11• 使用C++11 lambda匿名函數來編寫槽函數• 更好的Unicode字符串常量 QStringLiteral• Q_DECL_CONSTEXPR for constexpr• Q_STATIC_ASSERT and Q_STATIC_ASSERT_X• auto• 右值引用/移動構造函數• More… CONFIG += c++11 14. QtCore: JSON• QJsonArray• QJsonDocument• QJsonObject• QJsonParseError• QJsonValue• QJsonObject:iterator 擴展模塊QJsonDB : 構建在JSON庫之上的高性能Key-Value數據庫 15. QtGui QtQuick2QtWebkit QtQuick1QWidget Scene graph (in qtdeclarative)QPainter QBackingStoreQSurfaceQOpenGLQFont QImage … QWindowQScreenQOpenGLContextQAccessible QInputMethodQPA (Qt platform abstraction) WinMacWaylandX11 SymbianAndroid… 16. QtGui: QPA (Qt平台抽象層)讓Qt可以無處不在的秘密武器! LightHouse項目 17. QtGui: QPA (Qt平台抽象層)唯一的限制是你的想像力! Qt/Cacahttp://blog.forwardbias.in/2011/07/q tcaca-lighthouse-plugin.html 18. QtGui: QPA (Qt平台抽象層)使得迅速移植到新的系統平台成為可能!“Digia plans to quickly enable Qt onAndroid, iOS and Windows 8 platforms” http://www.digia.com/Qt/About-us/News/Digia-to-Acquire-Qt-from-Nokia/ 19. QtGui: QPA (Qt平台抽象層)qtbasesrcpluginsplatformsCocoaMinimal/minimalGLDirectfb Qnx WindowsEglfs XcbKmsOpenwfdLinuxfb 20. QtGui: QPA (Qt平台抽象層) 通過QPA可以控制的GUI功能:• Event dispatcher • Clipboard• Platform window• Drag• Platform backing store • Input method• Image paint engine • Accessibility• OpenGL context • Platform theme• Font database 21. QtGui: QPA (Qt平台抽象層)編寫自己的QPA plugin? #include class QMyQPAIntegration : public QPlatformIntegration { public:QMyQPAIntegration ();QAbstractEventDispatcher *guiThreadEventDispatcher() const;QPlatformWindow *createPlatformWindow(QWindow *window) const;QPlatformBackingStore *createPlatformBackingStore(QWindow *window) const;bool hasCapability(QPlatformIntegration::Capability cap) const;QPlatformPixmap *createPlatformPixmap(QPlatformPixmap::PixelType type) const;QPlatformOpenGLContext *createPlatformOpenGLContext(QOpenGLContext *context) const;QPaintEngine *createImagePaintEngine(QPaintDevice *paintDevice) const;//… }; 22. QtGui: OpenGLOpenGL現在是QtGUI的一部分,不再通過單獨的OpenGL模塊提供• QOpenGLContext• QOpenGLFramebufferObject• QOpenGLShaderProgram• QOpenGLFunctions• QOpenGLPaintDevice• …原有的OpenGL類通過單獨的QtOpenGL擴展模塊提供 23. QtQml & QtQuick QtQml QtDeclarative QtQuick 24. QtQml & QtQuick in Qt4.x QtDeclarative (QML/QtQuick)QGraphicsViewQtScriptQPainter Raster Engine GL EngineJSC QtGui 25. QtQml & QtQuick in Qt5 QtQuick QtQml Scene graph QWindowSurfaceV8 V4 (OpenGL (ES) 2.0)QtNetworkQtGui QtCore QPA 26. QtQml• QML語言核心模塊• 不再依賴QtQui, 僅依賴QtCore和QtNetwork• 命令行/服務器端QML開發? 27. QtQml: Javascript engine• JavascriptCore (JSC) => V8 • QtV8Private (qtjsbackend.git) • 更快,更好的GC,優秀的API設計• 不再通過QtScript中間層使用Javascript API 28. QtQml: V4, QML內部的Binding優化 • 一個輕量級的Javascript引擎 • 僅用於QML property binding優化目的 • 比V8還快得多,也小得多 29. QtQml: QML加載和編譯優化 • 加載和編譯均可異步完成• Qt.createComponent() with Component.Asynchronous• Loader {asynchronous:true} 30. QtQml: 其他增強• property variant => property var• Value types • QColor • Sequencetypes: QList, QList, QList, QList, QList< QString> and QStringList• Module API • qmlRegisterModuleApi()• Javascript import “.import” 31. QtQuick 2.0 How was QtQuick 2.0 developed? s/QDeclarative/QQuick/g 32. QtQuick 2.0• 基於OpenGL scene graph完全重寫全部類• public C++ APIs • QQuickView • QQuickWindow • QQuickItem • QQuickPaintedItem 33. Scene Graph 34. Scene GraphQQuickItem::updatePaintNode(…)(Rendering thread) Scene graph rendering nodes (Main thread) QML Items 35. Scene GraphNode types:• Root node• Basic node• Geometry node• Transform node• Clip node• Opacity node 36. Scene Graphpublic APIs:• QSGNode and subclasses• QSGNodeVisitor• QSGGeometry• QSGMaterial• QSGMaterialShader• QSGTexture 37. QtQuick 2.0Canvas item import QtQuick 2.0 Canvas { id:canvas width:200 height:200 contextType:”2d” onPaint : {var ctx = context; //or var ctx = canvas.getContext(“2d”); //use the HTML5 context2d API to draw anything you like } } 38. QtQuick 2.0Canvas item• Render targets: Canvas.Image, Canvas.FramebufferObject• Render strategies: Canvas.Immediate, Canvas.Cooperative,Canvas.Threaded• Tiled rendering: tileSize, canvasSize, canvasWindow 39. QtQuick 2.0 Animations• 完全重寫,不再依賴QtCore animation framework• 優化內存佔用和執行性能• 新的動畫元素• AnimationController• SpriteSequence• Sprite• AnimatedSprite 40. QtQuick 2.0Text• Text Rendering in the QML Scene Graphhttp://labs.qt.nokia.com/2011/07/15/text-rendering-in-the-qml-scene-graph/ 41. QtQuick 2.0粒子動畫系統 Particle SystemParticleSystem container/timer ParticlePainter Emmiterrender particlescreate particles Affectoralter particles 42. QtQuickTest: unit test in QMLWrite Quickly => Run Quickly => Test Quicklyimport QtQuick 2.0import QtTest 1.0TestCase {name: "BasicTests"function test_pass() { compare(2 + 2, 4, "2 + 2") }} 43. QtQuickTest: unit test in QML • TestCase • SignalSpy • Data driven test • QTest compatible APIs • more in qtdeclarativetestsautoqmltest 44. Qt5擴展模塊 / Qt5 Add-ons Modules30+ 擴展模塊:http://qt-project.org/wiki/Qt-Add-ons-Modules源自 Qt Mobility:QtContacts, QtOrganizer, QtVersit, QtLocation, QtBluetooth, QtSensors,QtServiceFramework, QtSystemInfo, QtPublishAndSubscribe, QtFeedback源自 Qt4.x: QtConcurrent, QtDBus, QtImageFormats, QtOpenGL,QtPrintSupport,QtQuick1, QtScript, QtScriptTools, QtSVG, QtTools,QtWidgets, QtXML, QtXMLPatterns, QtWebkitWidgets新增: Qt3D, QtGraphicalEffects, QtJsbackend, QtWayland,QtJsonDB 45. Demos 46. New QML Demos in Qt5 OpenGL Shaders Distance Field High-Quality Anti-Aliasing 47. New QML Demos in Qt5Qt5自帶QML演示程序•Shader effects•Animated sprites•Particle system•Canvas•Animations•Localstorage•XMLHttpRequestCheckout:qtdeclarativeexamplesdemos 48. New QML Demo in Qt5QtQuick 2.0QtMultimediaQtGraphicalEffects 49. New QML Demos in Qt5 更多Qt5演示請到Youtube QtStudios頻道觀 看,或者搜索Qt5關鍵字。 http://www.youtube.com/user/qtstudios 50. 全新開發模式 Open GovernenceModel 所有開發活動都在NPO非盈利組織 qt-project.org下完成 Home: http://qt-project.org Code review/CI : http://codereview.qt-project.org Bug tracking : http://bugreports.qt-project.org Mail list: http://lists.qt-project.org Wiki: http://wiki.qt-project.org Forum : http://qt-project.org/forums Doc : http://qt-project.org/doc 51. 全新開發模式 Open GovernenceModel 52. 全新開發模式 Open GovernenceModelContributors• 任何人都可成為qt-project的貢獻者,只要:• 在bugreports.qt-project.org註冊一個帳號來代表自己• 訂閱 http://lists.qt-project.org 的郵件列表來參與討論• 在bugreports.qt-project.org上提交缺陷報告/功能建議• 在codereview.qt-project.org 提交修復缺陷/新功能的代碼• 在codereview.qt-project.org上審查別人的代碼• 編寫文檔/參與討論• 在論壇/郵件列表/IRC上回答熱情的菜鳥的提問• 參與各類社區的活動來幫助推廣Qt 53. 全新開發模式 Open GovernenceModel Approvers• 有權在他/她了解的範圍內檢查/批准其他人貢獻的代碼• 當提交代碼時,Approvers不享有特權,他/她們的代碼同樣需要別人的檢查和許可,除了極少數例外情況• 當拒絕別人的代碼時,Approver有義務給出詳細和建設性的意見• Approver應該積極參與各類社區討論• 活躍的Contributors通過提名可以成為Approvers• 幹得不好會被收回權限 54. 全新開發模式 Open GovernenceModelMaintainers • Qt各個功能/模塊的技術領導者 • 對該負責領域的代碼質量負責 • 負責參與討論和制定該部分的發展方向 • 是該功能/模塊的默認代碼審查者當前Qt項目各個模塊的Maintainershttp://qt-project.org/wiki/maintainers 55. 全新開發模式 Open GovernanceModel Chief Maintainer • Qt最高技術決策者 • 維護Qt Open Governance Model正常運作 • 對Qt的發展做計劃 56. Qt Brisbane• 50+ 軟件工程師• 曾經負責開發Qtopia和後續的QtMobility項目• QML/QtQuick的老家• 現在負責的項目有 • Qt3D • QtLocation • QtDeclarative • QtMultimedia • QtSensors • QtSystems • Qt QA team • CI /Release/JIRA• Approvers/Maintainers權限將保留• We are looking for new career opportunities! 57. Qt的未來• qt-project.org 開放的開發模型,活躍的開源社區• 開放靈活的授權: GPL/LGPL 或者商業授權• 龐大的基於Qt的項目數量: • KDE, Maya, Skype, VLC, VirtualBox, Mathmatica,Dreamworks, Blackberry10, Adobe Photoshop Elements,Opera (Linux), Googe Earth• 投資Qt技術的眾多公司 58. 問題?