[Home]
[Edit this page]
[Recent Changes]
[Special Pages]
[Help]
QtProgramming
---------------------------------------------------
This tutorial covers Qt, a well-known development environment under Linux to write KDE applications. The latest Qt version can be obtained from Trolltech's website if its not already compiled in your distribution.
There is also a Windows version of Qt to compile with Visual C++, however, most people working with Qt use it on Linux.
The Qt package includes a designer and a compiler. With the designer you can only design the layout of your application. To compile it, you need to run gcc or another c++ compiler. This tutorial assumes that you use KDevelop to write Qt applications.
Before starting writing applications with Qt you first need to get a basic understanding of how the Qt class framework works since it is very different to other common frameworks like MFC or .NET.
The Qt class library is completely written in C++, yet it has implemented its own specific keywords. Below is a list of Qt specific keywords. The following code snippet shows how to use the emit keyword.
There are numerous other Qt specific keywords which will be added here in future.
Besides these Qt specific keywords, Qt makes extensive use of classes, Templates and core oop features like polymorphism, virtual functions etc. You can get an overview in the almost concise Qt reference manuals.
One of the core principles in Qt programming is the concept of Signals and Slots and their relation to widgets. I will explain this later in detail. To get an idea how this works you may look at the code below:
This is a simple program that creates a main window or widget with a pushbutton on it and a label that shows the text "Hello World . This program is not as tiny as the original C version yet it features a lot more functionality.
Widgets are a core concept in Qt. Widgets are objects of the user interface like buttons, controls, menus, windows etc. Anything that has to do with the applications user interface is a widget. All widgets are constructed on the heap with the new operator.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
QtProgramming
Qt Programming under Linux
---------------------------------------------------This tutorial covers Qt, a well-known development environment under Linux to write KDE applications. The latest Qt version can be obtained from Trolltech's website if its not already compiled in your distribution.
There is also a Windows version of Qt to compile with Visual C++, however, most people working with Qt use it on Linux.
The Qt package includes a designer and a compiler. With the designer you can only design the layout of your application. To compile it, you need to run gcc or another c++ compiler. This tutorial assumes that you use KDevelop to write Qt applications.
Qt: Or a new way of OOP programming
Before starting writing applications with Qt you first need to get a basic understanding of how the Qt class framework works since it is very different to other common frameworks like MFC or .NET. C++ and Qt
The Qt class library is completely written in C++, yet it has implemented its own specific keywords. Below is a list of Qt specific keywords. The following code snippet shows how to use the emit keyword.
class MyClass : public QObject
{
Q_Object
//the signals section
signals:
void printThis();
}
emit //used to send signals
emit printThis(); //trigger printThis event
There are numerous other Qt specific keywords which will be added here in future.
Besides these Qt specific keywords, Qt makes extensive use of classes, Templates and core oop features like polymorphism, virtual functions etc. You can get an overview in the almost concise Qt reference manuals.
Qt Basics: Signals, Slots & widgets
One of the core principles in Qt programming is the concept of Signals and Slots and their relation to widgets. I will explain this later in detail. To get an idea how this works you may look at the code below:int main() { //creating the main application object QApplication myapp(argc, argv); //Creating a new Widget QWidget* mywidget = new QWidget; mywidget->setGeometry(400,300,120,90); //adding a label to the widget QLablel* mylabel = new QLabel("Hello World",mywidget); mylabel->setGeometry(10,10,80,30); //adding a pushbutton to the widget QPusBbutton* myquitbutton = new QPushButton("Hello World",mywdiget); myquitbutton->setGeometry(10,50,100, 30); //connecting the pushbutton with the clicked() event QObject::connect(myquitbutton,SIGNAL(clicked(), &myapp, SLOT(quit())); //showing the main window and execute the app myapp.setMainWidget(mywidget); mywidget->Show(); return myapp.exec(); }
- include <qapplication.h>
- include <qlabel.h>
This is a simple program that creates a main window or widget with a pushbutton on it and a label that shows the text "Hello World . This program is not as tiny as the original C version yet it features a lot more functionality.
Understanding Widgets
Widgets are a core concept in Qt. Widgets are objects of the user interface like buttons, controls, menus, windows etc. Anything that has to do with the applications user interface is a widget. All widgets are constructed on the heap with the new operator.
[Edit this page] [Page history] [What links here] [Discuss this topic] [Printer Friendly]
