Sie sind auf Seite 1von 57

Introduction

Create more
Codeless

Deploy everywhere

Huynh Ngoc Doan 13-01-2009

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

What is QT?
Qt is the de facto standard C++ framework for high performance cross-platform software development.

Introduction

What is QT?
The Qt C++ framework has been at the heart of commercial applications since 1995. Qt is used by Adobe, Boeing, Google, IBM, Motorola,NASA, Skype, and by numerous smaller companies and organizations.

Introduction

What is QT?

Introduction

Adobe Photoshop Elements Album

Google Earth

QT on Linux and WinCE

Agenda
What is QT? QT architecture New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Product Architecture
GUI Introduction

Multi Language s Help, Everything here

Build project

Qt's Architecture

Introduction

Qts functionality is built on the low-level APIs of the platforms it supports. This makes Qt flexible and efficient, and enables Qt applications to fit in with single-platform applications.

For who are interested in Java


Play it yourself and tell me more

Introduction

Qt Jambi exposes the Qt API to Java applications, allowing highly portable applications to be written that take full advantage of C++ code for performance while looking and feeling native on each platform.

Introduction

Qt for C++ Development

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Install QT
What available on the Market? View qt-win-commercial-4.4.1-vs2008.exe the QT frame work qt-vsintegration-1.4.1.exe the plug-in tool for Visual Studio

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Learn new terms


Widget
Every GUI controls in QT are called Widgets
Introduction

Signal/Slot
Signal is Signal which raised in the object when an event occurs Slot is Slot is a functionComing Soon called in order to response an signal Signals and slots are used for communication between objects An alternative to the callback technique

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Object Model
These classes form the basis of the Qt Object Model. QMetaClassInfo QMetaEnum Additional information about a class Meta-data about an enumerator

Introduction

QMetaMethod
QMetaObject QMetaProperty

Meta-data about a member function


Contains meta-information about Qt objects Meta-data about a property

QMetaType
QObject QObjectCleanupHandler QPointer QVariant

Manages named types in the metaobject system


The base class of all Qt objects Watches the lifetime of multiple QObjects Template class that provides guarded pointers to QObjects Acts like a union for the most common Qt data types

Object Model - GUI

Introduction

QObject

Object Model - GUI


QWidget QDialog QMainWindow QMenu QDockWidget QComboBox QSplitterHandle

Introduction

QFileDialog

QAbstractPrintDialog

QFrame

QAbstractButton

QTabWidget

...

QAbstractScrollArea

QPushButton

QAbstractItemView

QListView

QTableView

QTreeView

QListWidget

QTableWidget

QTreeWidget

The QWidget class is the base class of all user interface objects.

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Common used Type


All generic type in C++
Int, float, double, char
Introduction

QString, QByteArray, QStringList (inherit QList) Template Collection Classes


QList<T>, QHash <T,T>

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Talk is cheap example please ?


main.cpp #include <QApplication> #include <QPushButton> int main(int argc, char *argv[]) { QApplication app(argc, argv); QPushButton hello("Helloworld!"); hello.show(); return app.exec(); }

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Project file *.pro


TEMPLATE - The template to use for the project. This determines whether the output of the build process will be an application, a library, or a plugin. CONFIG - General project configuration options. QT- Declaring Qt Libraries LIBS - Declaring Other Libraries HEADERS - A list of all the header files for the application. SOURCES - A list of all the source files for the application. FORMS - A list of all the .ui files (created using Qt Designer) for the application. TARGET - Name of the executable for the application. This defaults to the name of the project file. (The extension, if any, is added automatically). DESTDIR - The directory in which the target executable is placed. INCLUDEPATH - A list of any additional include paths needed for the application. DEPENDPATH - The dependency search path for the application. RC_FILE - Windows only: A resource file for the application. RESOURCES - A list of resource (.rc) files to be included in the final project Win32 - Scope the declarations for Window platform Example

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Signals and Slots


In GUI programming, when we change one widget, we often want another widget to be notified we want objects of any kind to be able to communicate with one another

Introduction

Signals and Slots


All classes that inherit from QObjector one of its subclasses (e.g., QWidget) can contain signals and slots Signals are emitted by objects when the changes are interesting to other objects Slots are used for receiving signals, but they are also normal member functions

Introduction

Declare signals and slots


class Counter : public QObject { Q_OBJECT public: Counter() { m_value = 0; } int value() const { return m_value; } public slots: void setValue(int value){ m_value = value; emit valueChanged(value); } signals: void valueChanged(int newValue); private: int m_value; };

Introduction

Connect/Disconnect signals and slots

Introduction

Connect/Disconnect signals and slots


We use: bool QObject::connect() static bool QObject::disconnect() static
Counter a, b; QObject::connect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int)));

Introduction

a.setValue(12); // a.value() == 12, b.value() == 12


b.setValue(48); // a.value() == 12, b.value() == 48 QObject::disconnect(&a, SIGNAL(valueChanged(int)), &b, SLOT(setValue(int))); a.setValue(36); // a.value() == 36, b.value() == 48

Execution of the code following the emit statement will occur once all slots have returned

Signals . Slots.
Introduction

Make I believe in your words

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

An Introduction to Model/View Programming

Introduction

Model-View-Controller (MVC) is a design pattern originating from Smalltalk that is often used when building user interfaces MVC consists of three kinds of objects. The Model is the application object, the View is its screen presentation, and the Controller defines the way the user interface reacts to user input If the view and the controller objects are combined, the result is the model/view architecture

Model\View
The model communicates with a source of data, providing an interface for the other components in the architecture The view obtains model indexes from the model, the view can retrieve items of data from the data source In standard views, a delegate renders / allow to edit the items of data

Introduction

Model\View
Signals from the model inform the view about changes to the data held by the data source. Signals from the view provide information about the user's interaction with the items being displayed. Signals from the delegate are used during editing to tell the model and view about the state of the editor.

Introduction

Introduction

Give me an example of Model\View

Model\View
Use this technique with QTableView, QTreeView, QListView Or You can use QTableWidget, QTreeWidget, QListWidget and dont need to know Model\View architecture

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

QMainWindow
Inherit from QWidget.
Introduction

A framework for building an application's user interface


QMainWindow has its own layout to which you can add QToolBars, QDockWidgets, a QMenuBar, and a QStatusBar

The layout has a center area that can be occupied by any kind of widget

QMainWindow - Layout

Introduction

Introduction

See QMainWindow in the real .

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Build your application


Run qmake command to generate the Hope You Makefile
So

Introduction

Run make or nmake to build the project I like to use tool Visual studio with the QT integration tool

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Designer tool
What you drag is what you get ?
Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Linguist Tool
Make all tribes understand your application!
Introduction

Linguist Tool
#include <QApplication> #include <QPushButton> #include <QTranslator> int main(int argc, char *argv[]) { QApplication app(argc, argv); QTranslator translator; translator.load("hellotr_la"); app.installTranslator(&translator); QPushButton hello(QPushButton::tr("Hello world!")); hello.resize(100, 30); hello.show(); return app.exec(); }

-Use tr() for the subclass of QObject -Use QObject::tr() static function -Or Use qApp->translate()

Introduction

Linguist Tool
Make file hellotr.pro:
SOURCES = main.cpp TRANSLATIONS = hellotr_la.ts
Introduction See in assistant Internationalization with Qt

Make file *.ts


Lupdate hellotr.pro All the quoted texts in tr(), QObjec::tr(), qApp>translate() are generated in the *.ts

Edit with Linguist tool Generate a .qm file from the .ts file
Choose File|Release from Qt Linguist's menu bar and Save

Run the program and see

Assistant

Introduction

The light of our life !

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Deploy application
Decide what is the target platform Remember dependency on the QT libraries And dont forget yourself-made libraries And your executable file Make a package as your way You do better than I !

Introduction

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Reference Links
QT is very wide and you can swim in it more
Introduction

http://trolltech.com/ http://doc.trolltech.com/ http://qtcentre.org/

And Success !!!!!!!!!!!

Agenda
What is QT? QT architecture Install QT New terms Object model Common used type First Example Project file Signals and Slots Model/View programming QMainWindow Build Application GUI Designer tool Linguist tool Deploy application Reference links Questions and Answers

Introduction

Wake up! Its over.


Introduction

Question ? or Have Lunch !!!

I refer

Das könnte Ihnen auch gefallen