Introduction to Qt - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

Introduction to Qt

Description:

The Qt toolkit is a multi-platform C GUI toolkit (class library) that has been ... graphical objects like buttons, scrollbars, dialog boxes, and toolbars is ... – PowerPoint PPT presentation

Number of Views:340
Avg rating:3.0/5.0
Slides: 16
Provided by: dalero
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Qt


1
Introduction to Qt
Department of Computer and Information
Science,School of Science, IUPUI
Dale Roberts, Lecturer Computer Science,
IUPUI E-mail droberts_at_cs.iupui.edu
2
The Qt Story
  • The Qt toolkit is a multi-platform C GUI
    toolkit (class library) that has been developed
    over a 6 year period.
  • The company Troll Tech AS was founded in 1994 to
    secure future development of Qt.
  • On May 20, 1995, Qt was made available under
    commercial and non-commercial GNU licenses. The
    non-commercial license grants any developer the
    right to use Qt to develop software for the free
    software community.
  • It was ten months before the first commercial
    license was purchased. The European Space Agency
    purchased the second.
  • Around 1997, Qt was chosen as the code basis for
    the KDE linux desktop environment.
  • Qt 3.0 was released in 2001 with Windows, Unix,
    Linux, Embedded Linux, and Mac OS X libraries.

3
Why GUI Toolkits?
  • Unix GUIs are typically based on the X Window
    System.
  • Primitive X11 functions let you draw primitive
    graphics like line and rectangles, set foreground
    and background colors, and (most importantly)
    interact with the user and send events back to
    the server.
  • The functions are network transparent, meaning
    that the server can display graphic on the local
    workstation or across the world. This is the
    same model as telnet.
  • Programming graphical objects like buttons,
    scrollbars, dialog boxes, and toolbars is very
    difficult using pure X11.
  • GUI Toolkits facilitate GUI programming under
    Unix.
  • Motif is both a GUI toolkit and popular GUI
    standard. Dalheimer argues that it is does not
    support type safety and is awkward compared to
    Qt. However, Qt does support the Motif
    look-and-feel as well as Windows.

4
Why Cross-Platform GUI toolkits
  • Increases target market.
  • May provides the same look-and-feel across
    platform. Reduces training and documentation
    costs.

5
Stategies for Implementing Cross-Platform GUIs
  • API Layering Mapping one API to many others
  • Example wxWindows Win32 API on top of Motif
    or Xt API under Unix.
  • Advantages easy to write, 100 compatible
    native look and feel.
  • Disadvantages
  • slower
  • problems mapping to vastly different API
    architectures
  • Lowest common denominator i.e. no pop-up help
    anywhere
  • Objects required a C wrapper to work with them
    in C

6
Stategies for Implementing Cross-Platform GUIs
  • API Emulation Implement a full API emulation
    (programming gaps where APIs to not directly map)
  • Examples MainWin and Wind/U Win32 API on top
    of Motif or Xt API under Unix.
  • Advantages Running on native platform requires
    no emulation, and is therefore fast. Provides
    full emulation. I.e. you can run Word under
    Unix.
  • Disadvantages
  • slower on emulated platforms
  • towers of layers MFC on Win32 on Motif on Xt on
    X11
  • toolkit harder to emulate
  • Problems with undocumented features
  • No direct support for C. APIs still needs a
    C wrapper.

7
Stategies for Implementing Cross-Platform GUIs
  • GUI Emulation Complete API written on top of
    primitive graphics (i.e. supported by all GUI
    OS). Each widget is drawn by the toolkit.
  • Examples Qt (C) and GTK (C)
  • Advantages
  • Faster because toolkit layer talks directly to
    OS.
  • Easy to change display style from within
    application Motif style under Windows, or
    Windows style under Unix.
  • Widgets are implemented as C classes and can be
    inherited from directly in client code. (This is
    the reason Qt is chosen instead of GTK)
  • Disadvantages
  • Does not support porting of existing programs
    (i.e. no Word under Unix).
  • More work to create implementations for every OS
    release for every target platform. This means Qt
    support lags behind OS releases. Impacts not
    only Qt but any widgets created by user
  • Emulation of look-and-feel is not 100 exact.

8
Qt Assistant
  • All documentation is available through the
    trolltech web site.
  • Qt Assistant is a Qt help browser that runs under
    Windows.
  • It has with search and indexing features that
    make it quicker and easier than the web.

9
A Simple Example/ HelloWorld.cpp /
  • 1 include ltqapplication.hgt
  • 2 include ltqlabel.hgt
  • 3
  • 4 int main(int argc, char argv)
  • 5
  • 6 QApplication myapp(argc, argv)
  • 7
  • 8 Qlabel mylabel new Qlabel(Hello
    World, 0)
  • 9 mylabel-gtresize(100, 200)
  • 10
  • 11 myapp.setMainWidget(mylabel)
  • 12 mylabel-gtshow()
  • 13 return myapp.exec()
  • 14

10
Line-by-line
  • 1 include ltqapplication.hgt
  • 2 include ltqlabel.hgt
  • Always include any Q types referenced in code.
  • 6 QApplication myapp(argc, argv)
  • Creates an object to manage application-wide
    resources. Passes argc and argv because Qt
    supports a few command line arguments of its own.
  • Qlabel mylabel new Qlabel(Hello World, 0)
  • Creates a QLabel widget on the heap. A widgets
    is any visual element in a user interface.
    Widgets can contain other widgets. For example a
    window may contain a QMenuBar,0 QToolBar,
    QStatusBar, and other widgets. The 0 parameters
    says that that the label is a stand-alone window,
    is not inside another window.

11
Line-by-line
  • 9 mylabel-gtresize(100, 200)
  • Invokes the resize() member function.
  • 11 myapp.setMainWidget(mylabel)
  • Make the label the main application widget. This
    means that closing the label windows closes the
    application.
  • 12 mylabel-gtshow()
  • Invoke the show() member function to make the
    label visible. All widgets are created invisible
    so that their properties can be manipulated
    without flickering. For example, you would show
    a widget and then change its size and color. You
    would change the size and color first, and then
    show the widget.
  • 13 return myapp.exec()
  • Passes control of the application to Qt. At this
    point the application goes into event-driven
    mode. It will just sit there until the user does
    something to create an even. This is the same
    concept as Word. Word starts and waits for the
    user to do something.

12
Events
  • Signals emit events
  • declare as signals, otherwise normal member
    functions
  • You don't implement them. Rather, you send them
    with the (new) keyword emit
  • E.g. emit(sliderChanged(5))
  • Slots receive and handle events
  • Normal member functions declared as slots
  • Connect must connect signals to slots
  • QObjectconnect( mymenu, SIGNAL(activated(int)),
    myobject, SLOT(slotDoMenuFunction(int)) )
  • moc meta object compiler (preprocessor) converts
    these new keywords to real C

13
Widgets
  • Base class for all UI widgets
  • Properties
  • width, height, backgroundColor, font,
    mouseTracking, backgroundPixmap, etc.
  • Slots
  • repaint, show, hide, move, setGeometry,
    setMainWidget, etc.
  • Signals
  • mouseMoveEvent, keyPressEvent, resizeEvent,
    paintEvent, enterEvent, leaveEvent, etc.

14
Other Features of Qt
  • The Qt Paint Engine
  • QPainter is highly optimized and contains several
    caching mechanisms to speed up drawing.
    Under X11, it caches GCs (graphics
    contexts), which often make it faster than
    native X11 programs.
  • QPainter contains all the functionality one would
    expect from a professional 2D graphics library.
    The coordinate system of a QPainter can be
    transformed using the standard 2D transformations
    (translate, scale, rotate and shear).
  • Qt supports Open GL for 3D graphics.
  • Qt also contains a set of general purpose classes
    and a number of collection-classes to ease the
    development of multi-platform applications.
  • Qt has platform independent support for the
    operating system dependent functions, such as
    time/date, files/directories and TCP/IP sockets.

15
Acknowledgements
  • Plantinga, Harry. Calvin College
  • Trolltech Tutorials.
  • pages.cpsc.ucalgary.ca/ saul/hci_topics/topics/hi
    story.html
Write a Comment
User Comments (0)
About PowerShow.com