QT Programming QT Programming Ruku Roychowdhury. Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally.

Slides:



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

CSCI 160 Midterm Review Rasanjalee DM.
Lecture 4: Embedded Application Framework Qt Tutorial Cheng-Liang (Paul) Hsieh ECE 424 Embedded Systems Design.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
Lecture 2: Object Oriented Programming I
CIS162AD Inheritance 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Constructors & Inheritance.
Advanced Object-Oriented Programming Features
Polymorphism. Lecture Objectives To understand the concept of polymorphism To understand the concept of static or early binding To understand the concept.
C++ fundamentals.
QT Intro. 김기형
L8: Qt4 Concept Qt Module QObject QObject Model Signal and Slot Qt Event Loop.
C# Event Processing Model Solving The Mystery. Agenda Introduction C# Event Processing Macro View Required Components Role of Each Component How To Create.
Qt Igor November 8, 2002 Friday’s HENP Group Meeting.
1 Chapter 14-2 Object- Oriented Software Development Dale/Weems.
OOP Languages: Java vs C++
Programming Languages and Paradigms Object-Oriented Programming.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Introduction to .Net Framework
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
Java and C++, The Difference An introduction Unit - 00.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
Blanchette and Summerfield, Ch. 2
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
C# Programming Fundamentals of Object-Oriented Programming Fundamentals of Object-Oriented Programming Introducing Microsoft.NET Introducing Microsoft.NET.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
Inheritance and Polymorphism Daniel Liang, Introduction to Java Programming.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
An Object-Oriented Approach to Programming Logic and Design Fourth Edition Chapter 6 Using Methods.
CS212: Object Oriented Analysis and Design Lecture 9: Function Overloading in C++
ECE122 Feb. 22, Any question on Vehicle sample code?
Object-Oriented Design CSC 212. Announcements This course is speeding up and we are starting new material. Please see me if you feel this is going too.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
C++ Programming Basic Learning Prepared By The Smartpath Information systems
Applications Development
Programming in Java CSCI-2220 Object Oriented Programming.
Object Oriented Software Development
Creational Pattern: Factory Method At times, a framework is needed to standardize the behavior of objects that are used in a range of applications, while.
C# Programming: From Problem Analysis to Program Design1 10 Advanced Object-Oriented Programming Features C# Programming: From Problem Analysis to Program.
Introducing Allors Applications, Tools & Platform.
CIS162AD Inheritance Part 3 09_inheritance.ppt. CIS162AD2 Overview of Topics  Inheritance  Virtual Methods used for Overriding  Abstract Classes and.
Confidential © 2008 Teleca AB Creating Custom Widgets Author: Patricia Jiang Date: July 29, 2010 Version: 1.0 Teleca Chengdu.
M1G Introduction to Programming 2 5. Completing the program.
Object Oriented Programming
GUIs Basic Concepts. GUI GUI : Graphical User Interface Window/Frame : a window on the screen Controls/Widgets : GUI components.
Introduction to Object-Oriented Programming Lesson 2.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Wel come To Seminar On C#.
1 C# - Inheritance and Polymorphism. 2 1.Inheritance 2.Implementing Inheritance in C# 3.Constructor calls in Inheritance 4.Protected Access Modifier 5.The.
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
CH10 Supplementary Material Prepared by Fatimah Alakeel Oct 2010.
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA ‏ Properties of Object Oriented Programming.
Georgia Institute of Technology More on Creating Classes Barb Ericson Georgia Institute of Technology June 2006.
Defining Data Types in C++ Part 2: classes. Quick review of OOP Object: combination of: –data structures (describe object attributes) –functions (describe.
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
1. 2 Qt Toolkit ● C++ toolkit for cross-platform GUI application development – GUI functions (GUI = graphical user interface) – Data access components,
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Inheritance and Polymorphism
Continuing Chapter 11 Inheritance and Polymorphism
Qt Programming.
C# Event Processing Model
Java Programming Language
Custom Widgets & Events
Chapter 11 Class Inheritance
C++ Object Oriented 1.
Computer Science II for Majors
Presentation transcript:

QT Programming QT Programming Ruku Roychowdhury

Background QT is a cross platform application framework. Widely used to develop GUI applications. Originally developed by Norwegian company Trolltech. After Nokia's acquisition of TrollTech, now Nokia's Qt Development Frameworks division is enhancing QT.

Some Applications with QT Google Earth KDE Adobe Photoshop Album Skype VLC media player VirtualBox

Features Cross-platform application framework. Qt uses standard C++. Makes extensive use of Meta Object Compiler together with several macros to enrich the language. Can be used with many other languages by Language Binding.

C++ Features Procedural as well as Object oriented language Abstraction Inheritance –Allows Multiple inheritance Polymorphism –Runtime Polymorphism (Virtual functions) –Static Polymorphism (Function Overloading)

QT Class Hierarchy Multiple Inheritance

Event Handling Event handling is done by Signals and Slots Signal –Emitted when a particular event occurs (e.g., clicked()) –Qt widgets: predefined signals –Developer can create custom signals Slot –Function called in response to a signal –Qt widgets: predefined slots –Developer can create custom slots Connection: –connects signals to slots –established by developer – handled by Qt framework

Connections

Meta Object System Meta information not supported by standard C++ –QObject class Base class for objects that use meta-object system –Q_OBJECT macro Enables meta-object features –“moc” tool –Parses Q_OBJECT macro –Extends source code with additional functions (extra files) Used for: getting list of signals & slots, properties and text translation

Meta-Object Features Features provided by meta-object code: Signals and slots metaObject() –returns associated meta-object for the class className() –returns class name as a string, without requiring native run-time type information (RTTI) support through the C++ compiler inherits() –returns whether this instance inherits the specified QObjectclass tr() –translate strings for internationalization setProperty() and property() –set and get properties of object by Property name

Signals and Slots (in details) QT signals and slots are TYPE SAFE –Signals & slots have to have exactly same parameters –It does not give any compilation error / warning –But gives runtime error when executing connect(): –No connection if either sender or receiver doesn’t exist –Or if signatures of signal and slot do not match connect() returns boolean value indicating success

Multiple Signal-Slot Connections One signal can be connected to multiple slots and vice versa also holds good.

Demonstration Every QWidget has a set of predefined signals and slots. A QPushButton and QRadioButton has predefined signals such as clicked() which they inherit from QAbstractButton. Slots can be written for these predefined signals and can be called directly without associating through connect().

Custom Signals and Slots A custom signal and slot can also be created. Custom signals and slots can be created in user’s own classes. –E.g. mysignal signal in the code sample –E.g. myslot slot in the code sample These signals and slot need to be explicitly connected with the connect() statement. –E.g. QObject::connect(this,SIGNAL(mysignal()),this,SLOT(myslot())); in code sample

Example Converter Constructor converter2::converter2(QWidget *parent) : QWidget(parent), ui(new Ui::converter2) { ui->setupUi(this); ui->label->setText("Unit1"); ui- >label_2->setText("Unit2"); QObject::connect(this,SIGNAL(mysignal()),this,SLOT(myslot())); input=""; } Signal Void converter2::on_pushButton_2_clicked() { emit mysignal(); } Slot Declaration void converter2::myslot() { time_t now; time(&now); QString time=ctime(&now); ui->textEdit- >setText(time); }

Creating custom signals and slots in the QWidgets User can create his own custom signals and slots for a QWidget. User has to extend any widget to create his custom subclass of that widget. –E.g. customButton is extended from QPushButton. It has custom signal clicked(int id) and slot click() in addition to the predefined signals and slots in QPushButton class.

Example Custom Button Class class customButton: public QPushButton{ Q_OBJECT public: customButton(const QString& text, int id,QWidget* parent = NULL); customButton(const QString& text, QWidget* parent = NULL); private: static int nextId; int m_id; public slots: void click(); signals: void clicked (int id); };//Custom signal for CustomButton

Compilation Every class is declared in the header file. Every class is defined in the.cpp file. –For example, converter_2.h contains the class declarations –Converter_2.cpp contains the class definitions. converter_2.h moc_converter_2.cpp Moc parses.h file change the QT specific code to plain c++ code + converter_2.cpp Linker links both of these.cpp file

Meta Object Compilation const QMetaObject QObject::staticMetaObject method is used to have meta object of the class defined in.h files. Moc generated code places data into two arrays –qt_meta_data_ array In the qt_meta_data array moc creates a own line for every QMeta related item –qt_meta_stringdata_ array In the qt_meta_stringdata array moc puts all the method, parameter, slot, signal.

Contd. when a signal is called, QMetaObject::activate() is called with the signal’s name and the signal’s arguments. The activate() function then figures out which connections have been established and fetches the names for the appropriate slots. Then it calls qt_metacall with the slot names and the arguments given to the signal. the metacall function delegates this with the help of a large switch— case statement to the real slots.

Thank You