Qt Igor November 8, 2002 Friday’s HENP Group Meeting

Preview:

Citation preview

QtIgor

November 8, 2002

Friday’s HENP Group Meeting

What is Qt?

“…multiplatform C++ GUI application framework…”

“…Qt is fully object-oriented, easily extensible, and allows true component programming…”

Supported platforms

MS/Windows (MFC) : from 95 to XPUNIX (X11) : most popular flavorsMac OS X :Embedded : Linux with frame buffer support

“…Qt is also the basis of the popular KDE Linux desktop environment…”

Qt is a product of Trolltech (www.trolltech.com)

Commercially introduced in early 1996

Versions and availability

V2.x : Is free for non-commercial development for all platforms. Licenses: QPL or GPL

V3.x : has lots of new stuff compared to v2.x

Is free for non-commercial development for UNIX only. Licenses: QPL or GPL. 30 days free evaluation download is available for MS-Windows and Mac OS X.

Is available in two editions (see next slide) for commercial software development. Prices vary from $1240 to $4370 per license depending on the total number of clients and the Qt edition.

No royalty for resulting applications

Modules and EditionsModules vs Edition ProfessionalEnterpriseQt Base Modules (Tools, Kernel, Widgets, Dialogs) X X The platform-independent Qt GUI toolk it and utility classesQt Designer X X Visual Qt GUI builderIconview module X X Visualization of sets of pixmaps with user interaction.Workspace module X X Multiple Document Interface (MDI) supportOpenGL 3D Graphics module X Integration of Qt with OpenGLNetwork module X Platform-independent classes for sock ets, TCP, FTP and asynchronous DNS look up.Canvas module X Optimized 2D graphics area for visualization, diagrams, etc.Table module X Flexible and editable table / spreadsheetXML module X Well-formed XML parser with SAX interface and DOM Level 1.SQL module X SQL database access classes.

What makes Qt a “cool” stuff?

My personal opinion :

It provides “all in one” object oriented framework for the component programming – one of the main practices in the contemporary software development (not in HEP)

A collection of services provided through the framework for the applications developers is nearly complete (for majority of desktop applications). It includes famous “triad”:

• GUI (user interaction)• Database (persistency)• Networking (distributed programming)

QtDesigner

Signal-Slot Objects Communication Model

• Multi-platform applications development• Qt Object Model• QtDesigner• …

Most interesting features

#include <qapplication.h>#include <qlabel.h>

int main( int argc, char **argv ){ QApplication app( argc, argv ); QLabel hello( "<font color=blue>Hello <i>Qt!</i>“, "</font>", 0 );

app.setMainWidget( &hello ); hello.show(); return app.exec();}

Qt Object ModelQt is supposed to add an extra flexibility to the plain C++ Object Model with the following extensions :

- a mechanism for seamless object communication called signals and slots- queryable and designable object properties- events and event filters- contextual string translation for internationalization

- interval driven timers that make it possible to integrate many tasks in an event-driven GUI

- hierarchical and queryable object trees that organize object ownership in a natural way

- guarded pointers, QGuardedPtr, that are automatically set to 0 when the referenced object is destroyed, unlike normal C++ pointers which become "dangling pointers" when their objects are destroyed

Qt Object Model : 1

The Qt Object Model implementation :

- Standard C++ techniques, based on inheritance from QObject base class

- Meta Object System provided by Qt's own Meta Object Compiler (“moc”)

Signals and Slots

#include <qapplication.h>#include <qpushbutton.h>

int main( int argc, char **argv ){ QApplication app( argc, argv ); QPushButton quit( “Quit”, 0 );

QObject::connect( &quit, SIGNAL( clicked()), &app, SLOT ( quit()));

app.setMainWidget( &quit ); quit.show(); return app.exec();}

Meta Object System

Provides :

Signals and Slots mechanism for inter-object communication, runtime type information, and the dynamic property system

Is based on :

-the QObject class

-the Q_OBJECT macro inside the private section of the class declaration

- the Meta Object Compiler (moc) to handle C++ extensions

Meta Object System : 1

How it works :

A developer writes a file using Qt C++ extension

The moc reads a C++ source file. If it finds one or more class declarations that contain the Q_OBJECT macro, it produces another C++ source file which contains the meta object code for the classes that use the Q_OBJECT macro. Among other things, meta object code is required for the signal/slot mechanism, runtime type information and the dynamic property system.

The C++ source file generated by the moc must be compiled and linked with the implementation of the class (or it can be #included into the class's source file).

MOC Example

class MyClass : public QObject { Q_OBJECTpublic: MyClass( QObject* parent=0, const char* name=0 ); ~MyClass();signals: void mySignal();public slots: void mySlot();};

MOC Example : 1

class MyClass : public QObject { Q_OBJECT Q_PROPERTY( Priority priority READ priority WRITE setPriority ) Q_ENUMS( Priority )public: ...

enum Priority { High, Low, VeryHigh, VeryLow }; void setPriority( Priority ); Priority priority() const; };

QtDesigner Approach

QtDesigner Approach : 1

QtDesigner Approach : 2

Recommended