Getting started with Qt
kiran10182
(Talk | contribs) m (fixed the link) |
kamaljaiswal
(Talk | contribs) |
||
| Line 64: | Line 64: | ||
[[Image:Step7.jpg]] | [[Image:Step7.jpg]] | ||
| + | |||
| + | If you have more then one version of Qt for S60 installed the opt for the correct version as shown. | ||
| + | |||
| + | [[Image:Properties.JPG]] | ||
| + | |||
| + | [[Image:Properties1.JPG]] | ||
| + | |||
Revision as of 10:05, 10 January 2009
Article Metadata
Tested with
Compatibility
Article
Contents |
Introduction
This article is for beginners who desire to start development in Qt for S60. Before following the steps given here please make sure that Carbide.c++, S60 SDK and Qt for S60 are properly installed.
- Install Qt for S60 Temple release from here: Qt for S60 "Temple" pre-release
- Check this link for installation guide: How to install the package.
Prerequisite
- Carbide.c++ 2.0 does not automatically locate your Qt installation so you need to tell it where Qt is installed. This is done through the following settings:
Carbide.c++ preferences: Window >> Preferences >> Qt >> Add...
First Step
Open the Carbide IDE and click on File->New->Qt Project.
Second Step
New window will open on the screen. This will show the type of the application one can create. Click on "Qt GUI Widget" and then click Next.
Third Step
Give the name of the project and click on Next.
Fourth Step
In this step one has to select the SDK for which the project is to be created and click Next.
Fifth Step
In this window, click Next after selecting the module. For our example one has to click Next without selecting any extra modules.
Sixth Step
Here, the class name is required. By default it is the application name. Click on Finish to proceed.
After finishing these steps, the project is ready. Several files will have been created automatically as shown in the screenshot below.
If you have more then one version of Qt for S60 installed the opt for the correct version as shown.
Include Qt Views
- Include views for Qt from:
Carbide.c++ >> Windows >> Show View >> Other... >> Qt
- Select following views at minimal depending on the application:
- Qt C++ Widget Box
- Qt C++ Property Editor
- Qt C++ Signal Slot Editor
Adding controls
- Open Hello.ui and place the control from Qt C++ Widget Box
- We will add two push buttons and one text label in this article.
- The display text of an object can be changed by right clicking on object -> Change text...
- The name of an object can be changed as shown in the following screenshots.
Text label
Hello push button
Exit push button
Implementing Signal and Slot mechanism for Exit push button
- Open Hello.ui
- Open Qt C++ Signal Slot Editor view
- Click on
to add entry for handling events on control
- In this article we will handle events on "Exit" push button
- The application will terminate when the user clicks on the "Exit" push button
Sender
- Here "exitButton" is the sender of the signal
Signal
- Here we will select "clicked()" signal to be sent by "exitButton"
Receiver
- Here HelloClass is the receiver of this event handling mechanism.
Slot
- Here "Slot" is the action performed when "exitButton" will be "clicked()" and here we want to exit from the application therefore we will select "close()"
Implementing Hello push button
- We will implement Hello button event through coding in Hello.h and Hello.cpp files.
Header file
#ifndef HELLO_H
#define HELLO_H
#include <QtGui/QWidget>
#include "ui_Hello.h"
class Hello : public QWidget
{
Q_OBJECT
public:
Hello(QWidget *parent = 0);
~Hello();
public slots: //We have added this section to handle "clicked()" event on "helloButton"
void ShowHelloText(); // Fill the label text on clicking "Hello" button
private:
Ui::HelloClass ui;
};
#endif // HELLO_H
Source file
#include "Hello.h"
Hello::Hello(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
// Signal and slot mechanism for "helloButton"
QObject::connect(ui.helloButton, SIGNAL(clicked()), this, SLOT(ShowHelloText()));
}
Hello::~Hello()
{
}
//We have implemented the following function to display "HelloWorld!!!" text in TextLabel
void Hello::ShowHelloText()
{
ui.label->setText("HelloWorld!!!");
}
Output
Initial state
Hello button pressed state
Example application
- Extract this example application: Hello.zip
- Import .pro file from the above extracted application in your Carbide.c++ IDE.
Carbide.c++ >> Import >> Qt >> Qt Project >> Hello.pro
Feedback
- If you find any problem in creating your HelloWorld application in Qt, then please write your feedback in Comment page of this article. We will try to help you at our best.
- Raise your other Qt for S60 related questions in this discussion board section: Qt for S60 Discussion Boards




















