Www.evl.uic.edu QT GUI Programming CS340 – Software Design © 2009 – Jason Leigh University of Illinois at Chicago.

Slides:



Advertisements
Similar presentations
First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
Advertisements

Construction process lasts until coding and testing is completed consists of design and implementation reasons for this phase –analysis model is not sufficiently.
Sven Johannsen C++ User Group Aachen 01/08/15
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.
Aalborg Media Lab 23-Jun-15 Inheritance Lecture 10 Chapter 8.
Cosc 4755 Phone programming: GUI Concepts & Threads.
Chapter Day 9. © 2007 Pearson Addison-Wesley. All rights reserved4-2 Agenda Day 8 Questions from last Class?? Problem set 2 posted  10 programs from.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
QT Intro. 김기형
L8: Qt4 Concept Qt Module QObject QObject Model Signal and Slot Qt Event Loop.
LAMAD Symbian Qt install and deploy Installing Qt SDK and deploying Qt applications.
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.
Mobile Programming Lecture 1 Getting Started. Today's Agenda About the Eclipse IDE Hello, World! Project Android Project Structure Intro to Activities,
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
Java Beans.
ROOT Tutorials - Session 51 ROOT Tutorials – Session 8 GUI, Signal/Slots, Image Processing, Carrot Fons Rademakers.
Blanchette and Summerfield, Ch. 2
Bertrand Bellenot ROOT Users Workshop Mar ROOT GUI Builder Status & Plans ROOT & External GUI World MFC, FOX, Qt, PVSS… Snapshot of the Future.
Recap, Test 1 prep, Composition and Inheritance. Dates Test 1 – 12 th of March Assignment 1 – 20 th of March.
Welcome to CIS 083 ! Events CIS 068.
DUE Hello World on the Android Platform.
FLTK Tutorial.
Chapter 34 Java Technology for Active Web Documents methods used to provide continuous Web updates to browser – Server push – Active documents.
Graphical User Interface CSI 1101 N. El Kadri. Plan - agenda Graphical components Model-View-Controller Observer/Observable.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
FLTK Help Session By Richard Yu Gu CS 638 -Graphics Fall, 1999.
Object Oriented Software Development 9. Creating Graphical User Interfaces.
Adding a New Option to the Framework. Introduction This is intended as a step by step guide to adding a new action to the menu or toolbar. The order of.
GUIs in Java Swing, Events CS2110, SW Development Methods Readings: MSD, Chapter 12 Lab Exercise.
Ch 3-4: GUI Basics Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: GUI Components.
FLTK. Objectives Install and Use FLTK Widgets ◦Callbacks Handling event ◦System events ◦Mouse events ◦Keyboard events.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
Dale Roberts Introduction to Visual Programming Dale Roberts, Lecturer Computer Science, IUPUI Department of Computer and.
Creating Windows. How can we use Java to create programs that use windows (GUI applications)? How can we use Java to create programs that use windows.
GUI With GTK+ Under Linux Fanfan Xiong. Introduction GTK+ (GIMP toolkit) : A library for creating graphical user interfaces(GUI) Two examples developed.
-1- National Alliance for Medical Image Computing First Steps with Qt Julien Finet Kitware Inc. Jan. 05 th 2010.
Chapter 14 Applets and Advanced GUI  The Applet Class  The HTML Tag F Passing Parameters to Applets F Conversions Between Applications and Applets F.
Object Oriented Programming.  Interface  Event Handling.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 – Graphical User Interfaces Java Foundations: Introduction to Programming.
Confidential © 2008 Teleca AB Creating Custom Widgets Author: Patricia Jiang Date: July 29, 2010 Version: 1.0 Teleca Chengdu.
QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.
. 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.
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…
Creating a GUI Class An example of class design using inheritance and interfaces.
1 Event Driven Programs Rick Mercer. 2 So what happens next?  You can layout a real pretty GUI  You can click on buttons, enter text into a text field,
L10: Model-View-Controller General application structure. User Interface: Role, Requirements, Problems Design patterns: Model – View – Controller, Observer/Observable.
QT – Windows, menus, and such C++ GUI Programming with Qt 4 Qt 4.5 Reference Documentation Blanchette and Summerfield, Ch. 3.
Developing GUIs With the Eclipse Visual Editor, SWT Edition David Gallardo.
LCG AA Meeting 30 June 2004 Ilka Antcheva Graphics User Interface in ROOT.
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,
Qt What is Qt ● Not Apple Quick Time :) ● GUI Toolkit ● General Toolkit ● Multi Platform ●
Event Loops and GUI Intro2CS – weeks
HCI/CHI: Computer-Human Interaction
QT graphical user interface framework
Event Driven Programming
Mobile Application Development with MeeGo™ - Programming with SDK
Qt Programming.
Custom Widgets & Events
GTK + Programming.
Constructors, GUI’s(Using Swing) and ActionListner
Tonga Institute of Higher Education
A multi-platform GUI-building program
A multi-platform GUI-building program
Presentation transcript:

QT GUI Programming CS340 – Software Design © 2009 – Jason Leigh University of Illinois at Chicago

History of qt Why qt Basic qt software and components And library capabilities – e.g. ogl, networking Simple qt example Dialog example to teach about slots/signals

About Qt First became available in Developed by Haavard Nord (Trolltechh’s CEO) and Eirik Chambe-Eng. Both graduates with MS in CS from Norwegian Institute of Technology in Trondheim started writing the classes that eventually became Qt 1992 they came up with the notion of singals and slots 1993 they produced Qt’s 1 st graphics kernel and could implement their own widgets Their wives supported them for 2 years while they tried to form their company. ‘Q’ doesn’t mean anything. It was chosen because it looked good in an emacs font. ‘T’ was added to mean toolkit. May 20, 1995 Qt 0.9 was released on sunsite.unc.edu – Qt 4 was released with 500 classes, 9000 functions. Much more than just a GUI toolkit now.

Why Qt? There are many other GUI toolkits- wxWidgets, fltk, Zinc for example. See: For this class: – QT is more than just a widget set. – It has libraries for graphics, sound, networking, threading, I/O. – It has an integrated IDE (QT Creator) as well as a GUI designer (QT Designer). – It does not use callbacks as the mechanism for responding to GUI events (such as in fltk) – which is somewhat out dated. – It does not require inheriting classes just to create UI elements as in wxWidgets or Microsoft Foundation Class- or whatever it’s called today. This tends to result in the creation of far too many classes- e.g. a class for every button you want to instantiate. – It’s free. – It’s crossplatform. – I can make an application “go” in a few minutes. – It uses the notion of signals and slots- which are similar to Java Observer/Observables that help keep code decoupled so that they communicate primarily by sending events. One thing to keep in mind is that every toolkit has its day in the sun and then it will be replaced by something else. So don’t necessarily focus on learning the nitty gritty of each function of the toolkit. Instead think about how the design of the toolkit helps or hinders development problems.

Basic QT Software and Components Download it from: – Download the Qt SDK which will include QT libraries, QT Creator IDE and QT development tools. Homework needs to be turned in and work under Linux though you may develop on your platform of choice.

Hello Qt #include int main( int argc, char* argv[] ) { // Qapplication manages application-wide resources QApplication myapp( argc, argv ); // A label I want to show QLabel* mylabel = new QLabel( "Hello, world", 0 ); mylabel->resize( 120, 30 ); mylabel->show(); // Pass control of application to Qt- which enters its own event loop return myapp.exec(); }

To compile, you need to first: qmake –project Which creates a project file. Then you type: Qmake hello.pro Which generates a makefile Run your app and it looks like this:

You can also do this within Qt Creator Create a new Empty Qt4 Project. Then add a C++ source file to it and type in your code. Create a new Empty Qt4 Project. Then add a C++ source file to it and type in your code.

By the way… F1 provides you with context sensitive help. Also Qlabel lets you use HTML: Qlabel *label = new Qlabel(“ Hello Qt! ”);

Signals, Slots and Meta-Objects Signal is a method that is emitted rather than executed when called. You declare prototypes of signals that might be emitted. I.e. you declare them in the signals section of your class, but you do not implement them. Slot is a member function that can be invoked as a result of signal emission. You can connect any number of signals to any number of slots. When a signal is emitted all the slots that are connected to the signal are called- though the order is not defined.

MyClass.h #ifndef MYCLASS_H #define MYCLASS_H #include class MyClass : public QObject// Inheriting from QObject { Q_OBJECT// Marks that this class needs a Meta Object public: MyClass (int value, QObject *parent = 0); // Pass the parent is just something you // always do. int getValue(); public slots: // The setter member function is often a good candidate for a slot. void setValue(int value); signals:// This class emits the valueChanged signal whenever its value has been changed void valueChanged(int); private: int m_value; }; #endif // MYCLASS_H Meta-object is an object describing the object. In Qt meta-objects are instances of the class QMetaObject and contain info about the class such as name, super classes, signals, slots, etc.

MyClass.cpp #include "MyClass.h" MyClass :: MyClass(int val, QObject *parent) : QObject(parent) // We pass parent pointer to base class's constructor. { m_value = val; } void MyClass :: setValue(int val) { // If the value has not changed then do nothing- this prevents a loop from // potentially happening… if (m_value == val) return; // If value changed then emit the valueChanged signal. m_value = val; emit valueChanged(m_value); }

main.cpp #include #include "MyClass.h” int main(int,char**) { MyClass *val1 = new MyClass(1); MyClass *val2 = new MyClass(2); MyClass *val3 = new MyClass(3); QObject::connect(val1, SIGNAL (valueChanged(int)), val2, SLOT(setValue(int))); QObject::connect(val2, SIGNAL (valueChanged(int)), val3, SLOT(setValue(int))); QObject::connect(val3, SIGNAL (valueChanged(int)), val1, SLOT(setValue(int))); val1->setValue(99); // You can set any val and eventually all vals will // get updated. }

Meta-objects like Q_OBJECT, and macros like SLOT, SIGNAL, public slot, etc.. requires translation into proper C++ code. This is done by Qt’s Meta Object Compiler, moc. As part of the compilation process, Qmake runs moc to generate the necessary code. moc

Simple Interaction Example with Connections, Signals and Slots Make a button called Quit Using connect, when the button is pressed, a clicked() signal from the button is sent to the quit() slot of the application.

Widget Layout Example Change in spinBox signals the slider to adjust its value and vice versa. Create a layout manager. In this case one that handles horizontal layouts. It will know to automatically layout widgets that are added to it.

Layout managers are useful for dealing with situations where the window may get resized. Depending on the rules you set, the layout will behave accordingly.

Creating a Dialog Box Goal is to create something like this. Want to create its own C++ class with its own signals and slots.

Dialog Layout Widget Hierarchy

Diagram showing signals and slots (lets compare this to source code) Received by findClicked() Slot Received by enableFindButton( ) Slot Find Button Close Button lineEdit box Emits Clicked() signal Emits findNext() Signal for something else to receive… presumably your Search routine. Emits findPrevious() signal Emits textChanged signal Received by close() Slot Emits clicked() signal Depending on state of search backward checkbox