Dale Roberts Programming with Qt Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science,

Slides:



Advertisements
Similar presentations
What is a Computer Program? For a computer to be able to do anything (multiply, play a song, run a word processor), it must be given the instructions.
Advertisements

Lecture 2 - Introduction Objective C is used primarily for application development on Apple's Mac OS X and iPhone. On the Apple it is used together with.
Chapter 16 Graphical User Interfaces
First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
Chapter 16 Graphical User Interfaces John Keyser’s Modifications of Slides by Bjarne Stroustrup
Lecture 4: Embedded Application Framework Qt Tutorial Cheng-Liang (Paul) Hsieh ECE 424 Embedded Systems Design.
QT GUI Programming CS340 – Software Design © 2009 – Jason Leigh University of Illinois at Chicago.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
A Simple Motif Widget The basic steps involved in creating and displaying this or any other Motif widget are essentially the same. This is a shell widget.
QT Intro. 김기형
Wir schaffen Wissen – heute für morgen A.C.Mezger An EPICS Display manager with Qt The EPICS display manager MEDM is a very powerful tool with many features.
Dale Roberts Introduction to Qt Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science,
Platforms and tools for Web Services and Mobile Applications Introduction to C# Bent Thomsen Aalborg University 3rd and 4th of June 2004.
Oct ROOT 2002, CERN, Geneva Qt-Based Implementation of Low Level ROOT Graphical Layer By V.Fine.
Qt Igor November 8, 2002 Friday’s HENP Group Meeting.
Dale Roberts 8/24/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Java Beans.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Blanchette and Summerfield, Ch. 2
Josh Kilgore Obi Atueyi Tom Calloway Ye Tian 1 Software Engineering Spring 2010.
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
OS provide a user-friendly environment and manage resources of the computer system. Operating systems manage: –Processes –Memory –Storage –I/O subsystem.
DUE Hello World on the Android Platform.
Why Java? A brief introduction to Java and its features Prepared by Mithat Konar.
FLTK Tutorial.
Design Patterns Part two. Structural Patterns Concerned with how classes and objects are composed to form larger structures Concerned with how classes.
BLU-ICE and the Distributed Control System Constraints for Software Development Strategies Timothy M. McPhillips Stanford Synchrotron Radiation Laboratory.
CS 3131 Introduction to Programming in Java Rich Maclin Computer Science Department.
Using Qt for GUI development Brad Whitlock March 2002.
Building X Window GUIs with Motif The X Window System: Architecture Applications Sample code Review function (as time permits) … Introduce what it’s like.
Dale Roberts GUI Programming using Java - Introduction Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer.
Session 27 Swing vs. AWT. AWT (Abstract Window ToolKit) It is a portable GUI library for stand-alone applications and/or applets. The Abstract Window.
CE Operating Systems Lecture 3 Overview of OS functions and structure.
1 Chapter 12 GUI C/C++ Language Programming Wanxiang Che.
SE-3910 Real-time Systems Week 7, Class 1 – GStreamer – QT SE Dr. Josiah Yoder Slide style: Dr. Hornick Much Material: Dr. Schilling, Some from.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Cross-platform C++ development using Qt®
I Power Higher Computing Software Development Development Languages and Environments.
-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
N ATIONAL E NERGY R ESEARCH S CIENTIFIC C OMPUTING C ENTER Charles Leggett Callbacks May
Confidential © 2008 Teleca AB Creating Custom Widgets Author: Patricia Jiang Date: July 29, 2010 Version: 1.0 Teleca Chengdu.
Windows Programming, C.-S. Shieh, KUAS EC, Chapter 0 Overview.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
9-Nov-97Tri-Ada '971 TASH An Alternative to the Windows API TRI-Ada ‘97 Terry J. Westley
. The ideas behind Qt and a live demo Qt in Education.
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
1 Lecture 5: Interactive Tools: Prototypers (HyperCard, Director, Visual Basic), Interface Builders Brad Myers Advanced User Interface Software.
QT – Introduction C++ GUI Programming with Qt 4
SE-3910 Real-time Systems Week 7, Class 1 – Announcement – GStreamer – Bins Boardshots – QT Swing & Qt Signals & Slots – Code – Example SE Dr. Josiah.
Introduction to Objective-C Spring Goals An introduction to Objective-C As implemented by the Apple LLVM Compiler 4.0 (a.k.a. Clang) Only the basics…
Introduction to OOP CPS235: Introduction.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington Java Programs COMP 102 #3.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Developing GUIs With the Eclipse Visual Editor, SWT Edition David Gallardo.
CINT & Reflex – The Future CINT’s Future Layout Reflex API Work In Progress: Use Reflex to store dictionary data Smaller memory footprint First step to.
CSIS 123A Lecture 7 Static variables, destructors, & namespaces.
Today (or Thursday) Qt Thursday Quiz SE-2811 Slide design: Dr. Mark L. Hornick Content: Dr. Hornick Errors: Dr. Yoder 1 SE3910 Week 6, Lab.
Sung-Dong Kim Dept. of Computer Engineering, Hansung University Chapter 3 Programming Tools.
Lecture 1 Page 1 CS 111 Summer 2013 Important OS Properties For real operating systems built and used by real people Differs depending on who you are talking.
July FLTK The Fast Light Toolkit • A C++ graphical user interface toolkit • Can be used under X, Windows, MacOS • Supports OpenGL • Provides: – Interactive.
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
CIS 234: Object-Oriented Programming with Java
Applications Active Web Documents Active Web Documents.
CISC105 – General Computer Science
HCI/CHI: Computer-Human Interaction
Java Look-and-Feel Design Guidelines
QT graphical user interface framework
Qt Programming.
Constructors, GUI’s(Using Swing) and ActionListner
Presentation transcript:

Dale Roberts Programming with Qt Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and Information Science, School of Science, IUPUI

Dale Roberts Outline The Qt Story The Layered X Programming APIs Implementing Cross-Platform GUI Libraries A Simple Example Callback Function Signals and Slots Other Features of Qt

Dale Roberts GUI toolkits Windows – MFC (Microsoft Foundation Classes) Mac – MacOS Unix – many. Most popular: Motif (on which CDE is based). Specifies look and feel. (Difficult, error-prone, and not much fun.) QT: portable "framework" – also handles sending events to widgets Not based on layering (too slow to pass execution between layers) Not based on API emulation (slow; different platforms require different API) Based on GUI emulation (widgets are C++ classes)

Dale Roberts Signals and Slots Various widgets widgets Panes – splitter splitter Tables – table table XML parsing – tagreader tagreader Networking, sound, printing 2D graphics – drawlines canvas xform drawlinescanvasxformdrawlinescanvasxform OpenGL support – gear gear OpenGL widgets, pixmaps – glpixmaps glpixmaps

Dale Roberts The Qt Story The Qt toolkit is a multi-platform C++ GUI toolkit (class library) that has been developed over a 4 year period. The company Troll Tech AS was founded in 1994 to secure future development of Qt. Qt for X11 has a non-commercial license which grants any developer the right to use Qt to develop software for the free software community. Qt allows the user to choose between the Motif and the Windows look and feel.

Dale Roberts The Layered X Programming APIs

Dale Roberts Implementing Cross-Platform GUI Libraries Three typical approaches for developing a cross-platform product are to 1. “Dumb-down” the components 2. “Map” the components onto an existing API 3. “Smart-up” the components

Dale Roberts “Dumbing-down” Components API Layering - e.g. wxWindows - advantage: 1. easy to program 2. look-and-feel is 100% compatible with the native look-and-feel native look-and-feel - disadvantage: 1. slower 2. awkward control flow 3. typically provide the lowest common denominator of functionality of functionality 4. difficult to inherit widgets and specialize them

Dale Roberts “Mapping” Components API emulation - e.g. MainWin, Wind/U - advantage: 1. not necessary to emulate original platform - disadvantage: 1. too different for making API emulation very practical practical 2. emulated platform would be slower 3. unstable

Dale Roberts “Smarting-up” Components GUI emulation - e.g. Qt - advantage: 1. fastest 2. changeable style 3. easy to inherit widgets and to redefine its behavior behavior - disadvantage: 1. can’t 100% exact 2. codes has to rewritten if a new widget be created

Dale Roberts A Simple Example /* HelloWorld.cpp */ 1 #include 1 #include 2 #include 2 #include 3 4 int main(int argc, char **argv) { 4 int main(int argc, char **argv) { 5 6 QApplication myapp(argc, argv); 6 QApplication myapp(argc, argv); 7 8 Qlabel *mylabel = new Qlabel(“Hello World”); 8 Qlabel *mylabel = new Qlabel(“Hello World”); 9 mylabel->resize(100, 200); 9 mylabel->resize(100, 200);10 11 myapp.setMainWidget(mylabel); 12 mylabel->show(); 13 return myapp.exec(); 14 }

Dale Roberts Callback Function One of the most feared and hackish aspects of GUI programming has always been the dreaded callback-function. A register table for widget (e.g. Motif) - no type checking - example: 1. quit = XtVaCreateManagedWidget(……); 1. quit = XtVaCreateManagedWidget(……); 2. XtAddCallback(quit, XmNactivateCallback, 2. XtAddCallback(quit, XmNactivateCallback, QuitCallback, NULL); 3. void QuitCallback(Widget w, XtPointer 3. void QuitCallback(Widget w, XtPointer clientData, XtPointer callData){ clientData, XtPointer callData){ exit(0); exit(0); }

Dale Roberts Callback Function(cont) Virtual function(e.g. wxWindows) - too many classes need to inherit for all widgets - high dependence between GUI and kernel of application - would be slower in a inefficient vtable Macro(e.g. MFC 、 OWL) - message map was complicated and difficult to codeing - need additional preprocess, IDE or application builder

Dale Roberts Event Handling QT's new approach: signals and slots A widget sends out various signals Object methods can be declared as slots Compatible signals and slots can be connected or plugged together like a telephone switchboard (parameter types must match) Strict separation This strict separation between UI components and program elements lends itself to component-based programming Goal: separate UI from program logic

Dale Roberts Signals and Slots

Dale Roberts Signals and Slots (cont) advantage: - independent interface - type-safe - process transparence disadvantage: - not as fast as a direct function pointer call. ( A signal triggering a slot has been measured to ( A signal triggering a slot has been measured to approximately 50 microseconds on a SPARC2. ) approximately 50 microseconds on a SPARC2. )

Dale Roberts Signals and Slots(cont) 1 class PixmapRotator : public QWidget { 1 class PixmapRotator : public QWidget { 2 Q_OBJECT 2 Q_OBJECT 3 public: 3 public: 4 PixmapRotator(QWidget *parent=0, const char *name=0); 4 PixmapRotator(QWidget *parent=0, const char *name=0); 5 public slots: 5 public slots: 6 void setAngle(int degrees); 6 void setAngle(int degrees); 7 signals: 7 signals: 8 void angleChanged(int); 8 void angleChanged(int); 9 private: 9 private: 10 int ang; 11 }; 12 void PixmapRotator::setAngle( int degrees ) { 13 degrees = degrees % 360;// keep in range 13 degrees = degrees % 360;// keep in range 14 if(ang == degrees) 15 return; // actual state change? 16 ang = degrees; // a new angle 17 emit angleChanged(ang); // tell world } 19 QObject::connect(scrollBar, SIGNAL(valueChanged(int)), rotator, SLOT(setAngle(int)));

Dale Roberts Signals and Slots(cont) Qt meta object compiler (moc) - It parses C++ header files and generates C++ code necessary for Qt to handle signals and slots. The signals, necessary for Qt to handle signals and slots. The signals, slots and emit keywords are macros, so the compiler slots and emit keywords are macros, so the compiler preprocessor changes or removes them. preprocessor changes or removes them. How to do? 1. moc –o moc_file.moc moc_file.cpp moc_file.h 1. moc –o moc_file.moc moc_file.cpp moc_file.h 2. #include “moc_file.moc” 2. #include “moc_file.moc”

Dale Roberts Defining Signals and Slots New C++ syntax for defining signals and slots, added to public, private, etc. class myClass : public Qobject { Q_OBJECT//required macro, no semicolon …signals: void somethingHappened(); … public slots: void slotDoSomething(); … private slots: void slotDoSomethingInternal(); …};

Dale Roberts 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 QObject::connect( mymenu, SIGNAL(activated(int)), myobject, SLOT(slotDoMenuFunction(int)) ); moc: meta object compiler (preprocessor) converts these new keywords to real C++

Dale Roberts 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.

Dale Roberts Qt, a GUI toolkit Events processed with signals and slots signal generates an event, e.g., button push slot processes the event, e.g., pop up a file dialog box QPushButton * quitB = new QPushButton(“Quit”,...,...); connect (quitB, SIGNAL(clicked()), qApp, SLOT(quit()); qApp is a global variable, of type QApplication one QApplication per program defined first in main() main returns qApp.exec() SIGNAL and SLOT are macros, expanded by a meta-object compiler (moc) moc generates.cpp files from user-defined Qt subclasses

Dale Roberts Designing GUI’s What about Designing GUIs? Design decisions: who designs the GUI? What (if anything) do you need to know about app internals? Qt expertise, who has it? [remember, Java on the horizon] Implementation Lay out the GUI [draw it, sketch it] get the main widgets up and running, but not connected develop methods/events that are application specific develop commands, menus, buttons, etc. Compiling using moc, Qt classes, seeMakefile

Dale Roberts Other Features of Qt The Qt Paint Engine - QPainter is highly optimized and contains several caching mechanisms to speed up drawing. Under X11, caching mechanisms to speed up drawing. Under X11, it caches GCs (graphics contexts), which often make it it caches GCs (graphics contexts), which often make it faster than native X11 programs. faster than native X11 programs. - QPainter contains all the functionality one would expect from a professional 2D graphics library. The coordinate from a professional 2D graphics library. The coordinate system of a QPainter can be transformed using the system of a QPainter can be transformed using the standard 2D transformations (translate, scale, rotate and standard 2D transformations (translate, scale, rotate and shear). shear).

Dale Roberts Other Features of Qt(cont) Support Classes - Qt also contains a set of general purpose classes and a number of collection-classes to ease the development of number of collection-classes to ease the development of multi-platform applications. multi-platform applications. - Qt has platform independent support for the operating system dependent functions, such as time/date, system dependent functions, such as time/date, files/directories and TCP/IP sockets. files/directories and TCP/IP sockets.

Dale Roberts Acknowledgements Plantinga, Harry. Calvin College Trolltech Tutorials.