Qt


Qt (pronounced officially in English cute ( / kjuːt / ) but commonly pronounced QT ( /kjuː.tiː/ ) 2 ):

  • An object-oriented API developed in C ++ by Qt Development Frameworks , a subsidiary of Digia . Qt provides components for GUI ( widgets ), data access, network connections, management execution son , analysis, XML , etc. ;
  • In some respects it resembles a framework when used to design graphical interfaces or to design the architecture of its application using the mechanisms of signals and slots for example.

Qt allows the portability of applications that use only its components by simply recompiling the source code. The supported environments are Unix ( including GNU / Linux ) that use the X Window System or Wayland , Windows , Mac OS X and also Tizen graphics system . Being a cross-platform software library attracts a large number of people who have the opportunity to broadcast their programs on the main existing OS.

Qt supports bindings with more than a dozen languages ​​other than C ++, such as Ada, C #, Java, Ruby, Visual Basic, etc.

Qt is known as the framework for the KDE graphical environment , one of the default desktop environments for several GNU / Linux distributions .

History

This is the Norwegian Institute of Technology in Trondheim that Haavard Nord ( CEO of Trolltech ) and Eirik Chambe-Eng (President of Trolltech ) meet. In 1988 , Haavard Nord is charged by a company Swedish develop a software library in C ++ to manage a GUI , it’s the first time he begins to approach the subject 3 . Two years later, with Chambe-Eng, they develop a cross-platform application ( Unix , Macintosh and Windows ) and are seriously beginning to think about the design of a multi-

In 1991 , they began the development of this library. The next year, Chambe-Eng proposed the “signals and slots” principle, which became the cornerstone of Qt. And in 1993 , the core of Qt was ready and enabled computer scientists to develop their own graphic components. It was at the end of this year that Haavard Nord proposes to create a company to market their library 3 .

Quasar Technologies is theAnd renamed six months later in Troll Tech, then Trolltech, then Qt Software and finally Qt Development Frameworks . The beginnings are particularly difficult financially. But they have the chance to be married: their women support themselves 3 .

The project was named Qt because the Q character was pretty in Haavard’s Emacs writing , and the t came from Xt Xtoolkit . All pronouncing in English cute , which means “cute”. The t is tiny, do not pronounce cutie ( /kjuː.ti/ ): this is not an acronym (QT) 3 .

It’s in That Trolltech has its first customer, the Norwegian company Metis. And for almost a year, she has no other, making the company very fragile financially. His second client, the European Space Agency (ESA), bought ten licenses for him in March 1996 3 .

Qt1

The Is announced the first public version of Qt on the newsgroup comp.os.linux.announce 4 . And a year later version 0.97, then theVersion 1.0 is published and announced a few days later 5 .

It was in 1997 that the KDE project was launched by Matthias Ettrich (who was hired by Trolltech the following year). The latter makes the decision to use Qt as the base library. The fact that a project of this scale uses Qt will be a very good advertisement for Trolltech and its library. Since then, the links between Trolltech and KDE have only increased.

Qt2

The second major version of Qt is published in And a version for embedded systems , Qt / Embedded , now known as Qtopia , was published in 2000 . This latest version is designed for Linux and uses her directly framebuffer , bypassing the windowing system X11 (which is unsuitable for embedded systems) 6 .

Qt3 [ change | Change the code ]

The first two major versions of Qt are available only for X11 and Windows , support for Mac OS X comes with version 3.0, released in 2001 . Compared to version 2.0, this new version provides better support for internationalization , Unicode or even regular expressions such as Perl .

Qt4

The , Version 4 is published and improves notably the rendering engine , now called Arthur 7 , the separation between data and presentation and separates the library into modules:

  • QtCore : for non-graphical features used by other modules;
  • QtGui : for graphical components;
  • QtNetwork : for network programming;
  • QtOpenGL : for the use of OpenGL ;
  • QtSql : for use database SQL ;
  • QtXml : for manipulating and generating XML files ;
  • QtDesigner : to extend the functionality of Qt Designer, the GUI creation wizard;
  • QtAssistant : for using Qt 8 help ;
  • Qt3Support : to ensure compatibility with Qt 3.

To this is added for the commercial version under Windows two other modules related to the use of ActiveX : QAxContainer and QAxServer .

With the evolution of Qt 4, other modules are designed:

  • QtDBus : for interprocess communication using D-Bus (only in Unix from Qt 4.2);
  • QtSvg : for displaying images in SVG format (from Qt 4.1);
  • QtUiTools : to dynamically load graphical interfaces created with Qt Designer (from Qt 4.1);
  • QtTest : to perform unit tests (from Qt 4.1);
  • QtScript : for the evaluation of scripts using Qt Script (from Qt 4.3);
  • QtWebKit : WebKit web rendering engine port(from Qt 4.4);
  • QtXmlPatterns : to manipulate XML documents via XQuery and XPath (from Qt 4.4);
  • Phonon : integration of Phonon , framework multimedia KDE 4 , developed in collaboration with the community KDE (from Qt 4.4);
  • QtHelp : Replaces the QtAssistant module by allowing the use of the Qt help format within applications (from Qt 4.4);
  • QtScriptTools : various tools for QtScript as a debugger (from Qt 4.5);
  • QtMultimedia : various classes offering low-level multimedia features compared to Phonon (from Qt 4.6);
  • QtOpenVG : allows to use, if present, the hardware acceleration of OpenVG for vector images in 2D (from Qt 4.6);
  • QtDeclarative : allows the design of dynamic graphical interfaces using a declarative language (QML) (from Qt 4.7).

The , Nokia launches a friendly takeover bid to buy Qt and Trolltech . Trolltech, renamed Qt Software , becomes a division of Nokia. From then on, Nokia takes the decision To lower the maximum barriers to facilitate the adoption of Qt, which since is used by their developments internally:

  • Adding a more permissive license than the GPL , the LGPL ;
  • opening development to external developers by making available the filing of Qt 9 .

Nokia refocusing on Windows, in March 2011 it divested the business services and management of commercial licenses of Qt to the company Digia 10 . On August 9, 2012, it fully ceded the management of the Qt framework to Digia 11 for € 4.9 million (compared to the 150 million in 2008 12 ). Digia announces to extend Qt support to Android , iOS and Windows 8 .

Qt5

Qt 5.0 is released on 13 . Though marking major changes on many points (QML and JavaScript’s important role in creating graphical interfaces with Qt Quick, separation into independent modules to facilitate deliveries, layer of abstraction to facilitate portages, etc.) Switching to Qt5 breaks compatibility at source level to the minimum. In this way, the passage is much easier than for Qt4.

Qt 5.x versions use plugins necessary for the deployment of the program.

Qt Quick

Qt Quick is a framework free developed and maintained by Digia part of the Qt library. It provides the ability to create customizable and dynamic user interfaces with fluid transition effects declaratively. This type of dynamic interface is becoming more common, especially on smartphones. Qt Quick includes a declarative scripting language called QML similar to the XAML created by Microsoft for its WPF library .

Qt Quick and QML are officially supported since Qt 4.7 (with Qt Creator 2.1).

Licenses

The KDE graphical environment project used the Qt library from the outset, but with the success of this environment, a certain part of the open source community criticized the license of Qt which was proprietary and incompatible with the GNU GPL used by KDE . This problem was solved by the Trolltech company which put the GNU / Linux and UNIX versions of Qt under GNU GPL license when the developed application was also under GNU GPL. For the rest, it is the commercial license that comes into effect. This dual-license policy has been applied only for GNU / Linux and UNIX at first, but since Qt version 4.0 it is applied for all systems.

Founded in June 1998 , the KDE Free Qt Foundation is responsible for ensuring the availability of Qt for free software development. As part of an agreement with Trolltech , the foundation has the right to distribute Qt under a BSD style license if Trolltech cease the development of the free version for various reasons, including bankruptcy 14 . The takeover of Trolltech by Nokia onDoes not call into question the dual-license policy, the Finnish company even supports KDE 15 .

The , Trolltech announces that version 3 and 4 of Qt are from this date under license GPLv2 and GPLv3. This version change only applies to the free versions of Qt. So Qt version 3 for Windows, which is not free, does not see its license changed 16 . This change is part of the desire KDE also upgrade to version 3 of the GPL, in addition to version 2 already used 17 .

One year later, the , Trolltech announces that from Qt 4.5, Qt will also be available under the LGPL v2.1 license 18 . This new license allows the development of proprietary software , without requiring the purchase of a commercial license from Qt Development Frameworks. This change, made by Nokia to ensure that Qt is used by as many projects as possible, is made possible by the fact that Nokia can dispense with sales of commercial licenses, unlike Trolltech, which could not deprive itself of this source of Income 9 .

Architecture

General structure

The Qt API consists of classes with names prefixed by Q and each word beginning with a capital letter (ex:) QLineEdit, it is the typography CamelCase . These classes often have attributes of enumerated types declared in the namespace Qt19 . Apart from a pure object architecture, some basic functionalities are implemented by macros (string to be translated with tr, display on standard output with qDebug…).

The naming conventions of the methods are quite similar to those of Java: the lowerCamelCase is used, ie all words except the first are capitalized (ex indicatorFollowsStyle():), the modifiers are preceded by set, on the other hand, the Accessors simply take the name of the attribute (ex text()🙂 or start with isbooleans (ex 🙂 isChecked().

Object tree

Qt objects (those QObjectinheriting from ) can self-organize themselves as a tree . Thus, when a class is instantiated, we can define a parent object. This organization objects as a tree facilitates memory management because before a parent object is destroyed, Qt recursively calls the destructor of all children 20 .

This notion of object tree also makes debugging easier, via the call of methods like QObject::dumpObjectTree()and Object::dumpObjectInfo() 20 .

Compiler of meta-objects

The moc 21 (for Meta Object Compiler ) is a preprocessor which applied before compiling the source code of a Qt program generates meta-information relating to classes used in the program. These meta-information are then used by Qt to provide functions not available in C ++, such as signals and slots and introspection .

The use of such an additional tool marks the Qt programs of the standard C ++ language. This is seen by Qt Development Frameworks as a necessary compromise to provide introspection and signal mechanisms. Upon exiting Qt 1.x, implementations of templates in C ++ compilers do not sufficiently uniform 22 .

Signals and Slots

Main article: Signals and slots .

Signals and slots are an implementation of the observer design pattern . The idea is to connect objects to each other via signals that are transmitted and received by slots. From the point of view of the developer, the signals are represented as simple methods of the sending class, of which there is no implementation. These “methods” are hereafter called, prefixing “emit”, which designates the emission of the signal. For its part, the slot connected to a signal is a method of the receiving class, which must have the same signature (in other words the same parameters as the signal to which it is connected), but unlike signals, it must be implemented By the developer.

It is the MOC that is responsible for generating the C ++ code necessary to connect signals and slots.

Interface designer

Qt Designer, the interface designer.

Qt Designer is a software that allows to create Qt graphical interfaces in a user-friendly environment. The user, by drag-and-drop , places the GUI components and set their properties easily. The GUI files are formatted in XML and have the extension .ui 23 .

When compiling, a GUI file is converted to C ++ class by the utility uic. There are several ways for the developer to use this class 24  :

  • the instantiated directly connect signals and slots
  • the aggregate in a different class
  • the inheritance into a superclass and thus having access to all elements of the interface created
  • Generate it on the fly with the class QUiLoaderthat takes care of interpreting the XML file .uiand returning a class instanceQWidget

Qmake

Qt is wanting a portable development environment and having the OMC as an intermediate step before the phase compilation / editing links , it was necessary to design a production engine specific. This is how the program is designed qmake.

The latter takes as input a file (with the extension .pro) describing the project (list of source files, dependencies, parameters passed to the compiler , etc.) and generates a platform-specific project file. For example, under UNIX systems, qmakea Makefile is created that contains the list of commands to execute to generate an executable, with the exception of Qt-specific steps (generating C ++ classes when designing a GUI with Qt Designer, Generation of C ++ code to link signals and slots, adding a file to the project, etc.).

The project file is made to be very easily editable by a developer. It consists of a series of variable assignments. Here is an example for a small project:

TARGET = myApply
SOURCES = main.cpp mainwindow.cpp
HEADERS = mainwindow.h
FORMS = mainwindow.ui
QT + = sql

These statements require that the executable be named myApply , listing the source files, headers, and GUI files. The last line states that the project requires the SQL module of Qt.

Internationalization

Qt integrates its own translation system, which is not fundamentally different in the principle of the gettext library . According to the manual of Qt Linguist, internationalization is provided by the collaboration of three types of people: the developers , the project manager and translators 25 .

In their source code, developers enter strings in their own language. They must allow the translation of these strings using the method tr(). In case of ambiguity about the meaning of an expression, they can also indicate comments intended to help the translators.

The project manager declares the translation files (one for each language) in the project file. The utility lupdatescans the sources for strings to be translated and synchronizes the translation files with the sources. Translations files are files XML with the extension .ts .

Translators use Qt Linguist to fill in translation files. When translations are finished, the project manager can compile the files .ts using the utility lreleasethat generates binary files with the extension .qm , exploitable by the program. These files are read at runtime and the strings found there are substituted for those that were written by the developers.

Style

The library embeds various widget themes that give it a good visual integration on all platforms. On GNOME , Mac OS X and Windows desktop environments Qt applications have the appearance of native applications.

Qt allows you to customize the appearance of the various GUI components using the cascading style sheets (CSS) principle 26 .

Development Tools

Qt Development Frameworks provides a set of free software to facilitate the development of Qt applications:

  • Qt Designer is a graphical designer interface, it saves files .ui ;
  • Qt Assistant allows you to view the complete documentation of Qt offline;
  • Qt Linguist is a dedicated tool for translators, it allows them to open files .ts that contain the strings to translate, and to enter their translation;
  • Qt Creator is the integrated development environment dedicated to Qt and facilitates the management of a Qt project . Its text editor offers the main functions of syntax highlighting , fullness , indentation , etc. Qt Creator integrates the Qt Designer and Qt Assistant tools ;
  • Qt Demo presents a set of small programs (in executables and sources) that show the functionality offered by the library.
  • Qt Installer Framework is a tool for easily creating installation programs.

Although Qt Creator is presented as the Qt reference development environment, there are Qt modules for the Eclipse 27 and Visual Studio 28 development environments . There are other IDEs dedicated to Qt and developed independently from Nokia, such as QDevelop and Monkey Studio .

Bindings

The bindings exist in order to use Qt with other languages than C ++. Thus the languages Ada , C # and Visual Basic ( Qt # 29 ), D , F # (Qt #), Java ( Qt Jambi 30 ), OCaml , Perl , PHP , Python 31 , Ruby ( QtRuby ), Scheme can be used. 32

Uses

View category: Software using Qt .

More and more developers are using Qt, including among large companies. These include Google , Adobe Systems , Skype and NASA . The Digia site lists companies using Qt and applications based on Qt 33 .

Syntax

The classic ” Hello World ” in different languages: C ++ , Java (with QtJambi ), Python (with PyQt and PySide ) and C # (with Qyoto  [ archive ] ):

.pro

TEMPLATE + = app
QT + = widgets

C ++

#include <QApplication>
#include <QPushButton>
Int main ( int argc , char * argv [])
{
 QApplication app ( argc , argv );
 QPushButton button ( "Hello world!" );
 Button . Show ();
 Return app . Exec ();
}

Let us study these lines.

#include <QApplication> : Includes the library QApplication, it is necessary in the .pro add QT += widgetsor replace QApplicationby QtWidgets/QApplication.

#include <QPushButton>: Same as above, with the library QPushButton(by using it, one can not include QWidget, because QPushButtonuses it).

int main(int argc, char *argv[]) { : Function_type function_name (argument1, argument2) {(start of function).

QApplication app(argc, argv); : We create an object QApplicationwith name app, with arguments argcand argv.

QPushButton bouton("Hello world!"); : We create an object QPushButtonwith the name button and for argument "Hello world!".

bouton.show(); : We call the show method of the button object (by default the button is invisible).

return app.exec(); : We call the method execof app, and we return its result.

Java ( QtJambi )

Import com.trolltech.qt.gui.QApplication ;
Import com.trolltech.qt.gui.QPushButton ;
Public class HelloWorld
{
 public static void main ( String args [])
 {
 QApplication . Initialize ( args );
 QPushButton hello = new QPushButton ( "Hello World!" );
 Hello . Show ();
 QApplication . Exec ();
 }
}

Python ( PyQt )

From PyQt4 import QtGui , QtCore
import sys
App = QtGui . QApplication ( sys . Argv )
hello = QtGui . QPushButton ( "Hello World!" , None )
hello . Show ()
app . Exec_ ()

Python ( PySide )

From PySide import QtGui
import sys
App = QtGui . QApplication ( sys . Argv )
hello = QtGui . QPushButton ( "Hello World!" , None )
hello . Show ()
app . Exec_ ()

C # ( Qyoto )

Using System ;
Using Qyoto ;
Public class HelloWorld
{
 public static int Main ( String [] args ) {
 QApplication app = new QApplication ( args );
 QPushButton hello = new QPushButton ( "Hello world!" );
 Hello . Show ();
 Return QApplication . Exec ();
 }
}

Notes and references

  • This article is partially or entirely from the article titled ” Qt Quick ” (see list of authors ) .
  1. ↑ ( en ) ” Qt 5.8.0 released [ archive ]
  2. ↑ ( in ) Christian D. Kamm, ” pronunciation Qt during the release of the SDK 1.1 [ archive ] , Qt Studio , (AccessedAugust 3, 2011 ) .
  3. a , b , c , d and e ( in ) Jasmin Blanchette and Mark Summerfield, C ++ GUI Programming with Qt 4 , Prentice Hall,, 560 p. ( ISBN 978-0-13-187249-3 , read online  [ Archive ] ) , “A Brief History of Qt”.
  4. ↑ ( en ) ” Beta of Motif-like C ++ library available [ archive ] , Trolltech , (Accessed 13 December 2007 ) .
  5. ↑ ( en ) ” Qt 1.0 released (c ++ gui library) [ archive ] , Trolltech , (Accessed 13 December 2007 ) .
  6. ↑ ( en ) ” Qtopia Core [ archive ] , Trolltech , (Accessed 7 January 2008 )
  7. ↑ Online documentation Qt  [ archive ]
  8. ↑ this module, considered as obsolete, disappears in Qt 4.6. The only class which is part of it remains present for reasons of compatibility
  9. a and b Aaron Seigo, ” Qt goes LGPL!  ”  [ Archive ] , (Accessed 14 January 2009 )
  10. ↑ Nokia licenses Qt licenses to Digia  [ archive ]
  11. ↑ http://www.digia.com/en/Home/Company/News/Digia-to-acquire-Qt-from-Nokia/  [ archive ]
  12. ↑ Digia to pay Nokia € 4 million for Qt as framework heads to cross-platform future  [ archive ]
  13. ↑ http://qt-project.org/wiki/Qt_5.0  [ archive ]
  14. ↑ ( en ) ” KDE Free Qt Foundation [ archive ] , KDE (accessed 28 January 2008 )
  15. ↑ ( en ) ” Open letter to KDE and the Open Source community – Joint announcement [ archive ] , Trolltech and Nokia ,(Accessed 28 January 2008 )
  16. ↑ ( in ) ” Trolltech releases Qt under the GPL v3 license [ archive ] , Trolltech , (Accessed 19 January 2008 )
  17. ↑ ( en ) ” Projects / KDE Relicensing [ archive ] , KDE (accessed 19 January 2008 )
  18. ↑ ( en ) . ” LGPL License Option Added to Qt [ archive ] , Trolltech , (Accessed 14 January 2009 )
  19. ↑ http://doc.trolltech.com/qq/qq13-apis.html  [ archive ]
  20. a and b ( in ) ” Object Trees and Object Ownership [ archive ] , Qt Development Frameworks , 2009 (accessed 18 2009 June )
  21. ↑ ( en ) Using the moc  [ archive ]
  22. ↑ ( en ) Why does not Qt use templates for signals and slots?  [ Archive ]
  23. ↑ ( in ) ” Qt Designer’s UI File Format [ archive ] , Qt Development Frameworks , 2009 (accessed 17 2009 June )
  24. ↑ ( in ) ” Using a Designer .ui File in Your Application [ archive ] , Qt Development Frameworks , 2009 (accessed 17 2009 June )
  25. ↑ ( in ) ” Qt Linguist Manual [ archive ] , Qt Development Frameworks , 2009 (accessed 23 2009 June )
  26. ↑ ( in ) ” Qt Style Sheets [ archive ] , Qt Development Frameworks , 2009 (accessed 23 2009 June )
  27. ↑ ( in ) ” Qt Eclipse Integration for C ++ [ archive ] , Qt Development Frameworks , 2009 (accessed 23 2009 June )
  28. ↑ ( in ) ” Qt Visual Studio .NET Integration [ archive ] , Qt Development Frameworks , 2008 (accessed 23 June 2009 )
  29. ↑ https://techbase.kde.org/Languages/QtSharp  [ archive ]
  30. ↑ initially developed by Qt Development Frameworks , the support of this binding is abandoned inAnd its maintenance is left to the community as a result of the release of the source code
  31. ↑ PyQt , PySide , PythonQt  [ archive ]
  32. ↑ https://wiki.qt.io/Category:LanguageBindings  [ archive ]
  33. ↑ ( in ) Qt in Action  [ archive ]