Cross Platform Qt

  • 3,443 views
Uploaded on

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

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

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,443
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
1

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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