Cross Platform Qt Johan Thelin
Quick Bio <ul><li>Consultant – Qt/Linux </li><ul><li>Development
Articles, whitepapers, etc
Training www.stf.se  </li></ul><li>Member of
Co-organizes FSCONS embedded November 5-7 </li></ul>
The History of Qt
What is Qt <ul><li>A framework written in C++
For creating portable application source code – one source, multiple platforms
Produces native applications </li></ul>
The History of Qt <ul><li>Developed since 1991 by  Eirik Chambe-Eng and Haavard Nord
Trolltech founded in 1994
Acquired by Nokia 2008
Nokia Qt Development Frameworks </li></ul>
The History of Qt <ul><li>Originally Qt/X11 and Qt/Windows </li><ul><li>X11 used Free Qt License, later QPL
Windows was closed source </li></ul><li>Qt/OS X was released in 2001 (Qt 3.0) </li><ul><li>OS X was closed source </li></u...
2009 all platforms released under LGPL </li></ul>
The History of Qt <ul><li>The overall goal has been portable source code and the best framework </li><ul><ul><ul><ul><ul><...
Create More
Deploy Everywhere </li></ul></ul></ul></ul></ul></ul>
The Architecture of Qt
The Modules of Qt QtGui QtSql QtNetwork QtWebKit QtSvg QtOpenGL QtOpenVG QtMultimedia QtScript QtXml QtXmlPatterns Phonon ...
The Modules of Qt <ul><li>Modules are libraries in themselves
Can be activated or disabled at compile time
Allows tweaking of feature set and footprint
As easy as  CONFIG += sql network
All modules share the Qt API design
All modules fit together </li></ul>
Key Concepts <ul><li>The  QObject  class makes Qt convenient </li><ul><li>Simplified memory management
Signals and slots
Introspection
Properties </li></ul></ul>
QObject – Memory Mgmt <ul><li>Each  QObject  can have a parent
Parents delete all children upon destruction </li></ul>MyDialog::MyDialog(QWidget * parent ) : QDialog( parent ) { QPushBu...
Upcoming SlideShare
Loading in...5
×

Cross Platform Qt

3,635

Published on

A presentation on cross platform development using Qt help on the second foss-sthlm meeting.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,635
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "Cross Platform Qt"

  1. 1. Cross Platform Qt Johan Thelin
  2. 2. Quick Bio <ul><li>Consultant – Qt/Linux </li><ul><li>Development
  3. 3. Articles, whitepapers, etc
  4. 4. Training www.stf.se </li></ul><li>Member of
  5. 5. Co-organizes FSCONS embedded November 5-7 </li></ul>
  6. 6. The History of Qt
  7. 7. What is Qt <ul><li>A framework written in C++
  8. 8. For creating portable application source code – one source, multiple platforms
  9. 9. Produces native applications </li></ul>
  10. 10. The History of Qt <ul><li>Developed since 1991 by Eirik Chambe-Eng and Haavard Nord
  11. 11. Trolltech founded in 1994
  12. 12. Acquired by Nokia 2008
  13. 13. Nokia Qt Development Frameworks </li></ul>
  14. 14. The History of Qt <ul><li>Originally Qt/X11 and Qt/Windows </li><ul><li>X11 used Free Qt License, later QPL
  15. 15. Windows was closed source </li></ul><li>Qt/OS X was released in 2001 (Qt 3.0) </li><ul><li>OS X was closed source </li></ul><li>2005 all platforms released under GPL
  16. 16. 2009 all platforms released under LGPL </li></ul>
  17. 17. The History of Qt <ul><li>The overall goal has been portable source code and the best framework </li><ul><ul><ul><ul><ul><li>Code Less
  18. 18. Create More
  19. 19. Deploy Everywhere </li></ul></ul></ul></ul></ul></ul>
  20. 20. The Architecture of Qt
  21. 21. The Modules of Qt QtGui QtSql QtNetwork QtWebKit QtSvg QtOpenGL QtOpenVG QtMultimedia QtScript QtXml QtXmlPatterns Phonon QtDBus QtTest
  22. 22. The Modules of Qt <ul><li>Modules are libraries in themselves
  23. 23. Can be activated or disabled at compile time
  24. 24. Allows tweaking of feature set and footprint
  25. 25. As easy as CONFIG += sql network
  26. 26. All modules share the Qt API design
  27. 27. All modules fit together </li></ul>
  28. 28. Key Concepts <ul><li>The QObject class makes Qt convenient </li><ul><li>Simplified memory management
  29. 29. Signals and slots
  30. 30. Introspection
  31. 31. Properties </li></ul></ul>
  32. 32. QObject – Memory Mgmt <ul><li>Each QObject can have a parent
  33. 33. Parents delete all children upon destruction </li></ul>MyDialog::MyDialog(QWidget * parent ) : QDialog( parent ) { QPushButton *okButton = new QPushButton( this ); QPushButton *cancelButton = new QPushButton( this ); ... } MyWindow::useDialog() { MyDialog dlg(this); if(dlg.exec() == QDialog::Accepted) ... }
  34. 34. QObject – Signals and Slots <ul><li>Dynamic calling of functions </li><ul><li>One interface for all “callbacks”
  35. 35. Works seamless across thread boundaries
  36. 36. Creates re-usable components </li></ul></ul>class QPushButton : ... { ... signals : void clicked(); ... }; class QListWidget : ... { ... public slots : void clear(); ... }; connect (button, SIGNAL(clicked()), list, SLOT(clear()));
  37. 37. QObject – Signals and Slots <ul><li>Inside the button class
  38. 38. Signals and function pointer tables, etc are generated by the meta object compiler, moc
  39. 39. Invoked at compile time and generates additional vanilla C++ source code </li></ul>emit clicked();
  40. 40. QObject - Introspection <ul><li>moc extracts more information, e.g. class names and inheritance
  41. 41. This enables introspection </li><ul><li>Dynamic object creation, casting, method calling, etc
  42. 42. Great when creating language bindings
  43. 43. Makes RTTI work across library boundaries </li></ul></ul>
  44. 44. QObject - Properties <ul><li>QObject and moc also add support for properties, e.g.
  45. 45. Great when binding to dynamic languages
  46. 46. Great when serializing objects
  47. 47. Can be used to add extra information to existing classes. Useful in combination with visitor classes </li></ul>class QLabel : ... { Q_PROPERTY (QString text READ text WRITE setText ...) ... }
  48. 48. More Qt <ul><li>The power of C++ combined with the flexibility and ease of dynamic languages
  49. 49. Qt is more </li><ul><li>Great documentation
  50. 50. Large community
  51. 51. High quality code
  52. 52. etc </li></ul></ul>
  53. 53. Qt Today
  54. 54. Examples of Qt in Use <ul><li>KDE
  55. 55. Google Earth
  56. 56. Nokia N900 </li></ul>
  57. 57. Available Qt Platforms Official Ports <ul><li>X11
  58. 58. Windows
  59. 59. Mac OS X
  60. 60. Embedded Linux
  61. 61. Windows CE
  62. 62. Symbian
  63. 63. Maemo / MeeGo </li></ul>Other Ports <ul><li>OpenSolaris
  64. 64. Haiku
  65. 65. OS/2
  66. 66. iPhone
  67. 67. Android
  68. 68. webOS
  69. 69. Kindle DX
  70. 70. QNX
  71. 71. wxWorks </li></ul>
  72. 72. Available Qt Bindings <ul><li>C++
  73. 73. C# (.net)
  74. 74. Ada
  75. 75. Java
  76. 76. JavaScript
  77. 77. Lisp
  78. 78. Lua
  79. 79. Perl
  80. 80. PHP
  81. 81. Python
  82. 82. Ruby
  83. 83. etcetera </li></ul><ul><li>Qt is developed in C++
  84. 84. The QtScript module enables JavaScript integration
  85. 85. PyQt is very popular
  86. 86. The smoke bindings generator from KDE makes it easy to create more bindings </li></ul>
  87. 87. Qt Today <ul><li>The core value and main objective still holds true: portable source code
  88. 88. The goal of Qt is to blend in everywhere </li></ul>
  89. 89. Portability Tips and Tricks
  90. 90. Portability - Interfaces QStyle QCommonStyle QMotifStyle QWindowStyle QS60Style QProxyStyle QCDEStyle QMacStyle QPlastiqueStyle QWindowsXPStyle QCleanlooksStyle QGtkStyle QWindowsVistaStyle
  91. 91. Portability - Interfaces <ul><li>Not all custom widgets are style aware! </li></ul>void MyWidget::paintEvent(QPaintEvent *event) { QPainter painter(this); QStyleOptionFocusRect option; option.initFrom(this); style()->drawPrimitive (QStyle::PE_FrameFocusRect, &option, &painter, this); }
  92. 92. Portability - Backends ... QPainter QPaintEngine QRasterPaintEngine X11 Windows OpenGL SVG
  93. 93. Portability - Backends <ul><li>The QPainter acquires a raster engine through the QPaintDevice interface implemented by all QWidget classes </li></ul>void MyWidget::paintEvent(QPaintEvent *event) { QPainter painter(this) ; QStyleOptionFocusRect option; option.initFrom(this); style()->drawPrimitive(QStyle::PE_FrameFocusRect, &option, &painter, this); }
  94. 94. Backends <ul><li>For embedded Linux, there are a number of useful backends </li><ul><li>QKbdDriverPlugin
  95. 95. QMouseDriverPlugin
  96. 96. QScreenDriverPlugin </li></ul><li>For general use, there are even more </li><ul><li>Accessibility, fonts, icons, image loading and saving, styles, codecs, etc </li></ul></ul>
  97. 97. Portability - Hints <ul><li>Qt uses flags for platform specific features. The flags are ignored when they are not valid </li><ul><li>Qt::Drawer
  98. 98. Qt::Sheet </li></ul><li>On X11, the window manager can be a factor as it handles the window decorations, e.g. </li><ul><li>Qt::WindowMinimizeButtonHint
  99. 99. Qt::WindowSystemMenuHint </li></ul></ul>Mac OS X specific dialogs, gives you an ordinary dialog or window on other platforms.
  100. 100. Portability - Hints <ul><li>When hinting or using platform specifics – be aware of the limitations
  101. 101. Documentation: “ Indicates that the window is a Macintosh sheet. Since using a sheet implies window modality, the recommended way is to use QWidget::setWindowModality()... ” </li></ul>MyDialog::MyDialog(QWidget *parent) : QWidget(parent, Qt::Sheet ) { setWindowModality(Qt::WindowModal); ...
  102. 102. More Portability <ul><li>Defines make it possible to write dedicated code for each platform </li><ul><li>Q_OS_LINUX , Q_LITTLE_ENDIAN , etc </li></ul><li>It is possible to hook into platform specific events
  103. 103. It is possible to tweak the Qt build system to link against different libraries on different platforms
  104. 104. It is possible to enable or disable individual classes to streamline Qt
  105. 105. ... </li></ul>bool QWidget::x11Event (XEvent *event)
  106. 106. Portability <ul><li>In 99% of the cases no platform specific code is needed
  107. 107. As long as you stick to Qt APIs you do not have to worry about platforms – it just works </li></ul>
  108. 108. Thank you for your attention! [email_address]

×