×
Namespaces

Variants
Actions
Revision as of 17:26, 9 February 2009 by jaaura (Talk | contribs)

Archived:Getting started with Qt

From Nokia Developer Wiki
Jump to: navigation, search
Featured Article
Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Symbian
Article
Keywords: PushButton, TextLabel, Signal and Slot
Created: (29 Dec 2008)
Last edited: jaaura (09 Feb 2009)


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.


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...

Qt Preference.PNG

First Step

Open the Carbide IDE and click on File->New->Qt Project.

Step1.jpg


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.

Step2.jpg


Third Step

Give the name of the project and click on Next.

Step3.jpg


Fourth Step

In this step one has to select the SDK for which the project is to be created and click Next.

Step4.jpg


Fifth Step

In this window, click Next after selecting the module. For our example one has to click Next without selecting any extra modules.

Step5.jpg


Sixth Step

Here, the class name is required. By default it is the application name. Click on Finish to proceed.

Step6.jpg

After finishing these steps, the project is ready. Several files will have been created automatically as shown in the screenshot below.

Step7.jpg

If you have more than one version of Qt for S60 installed on your machine then opt for the correct version as shown below.

Properties.JPG

Error creating thumbnail: Image type not supported


Include Qt Views

  • Include views for Qt from:
  Carbide.c++ >> Windows >> Show View >> Other... >> Qt

QtView.png

  • Select following views at minimal depending on the application:
  1. Qt C++ Widget Box
  2. Qt C++ Property Editor
  3. Qt C++ Signal Slot Editor

Adding controls

  • Open Hello.ui and place the control from Qt C++ Widget Box

QtWidgetBox.png

  • 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

TextLabel.png

Hello push button

HelloButton.png

Exit push button

ExitButton.png


Implementing Signal and Slot mechanism for Exit push button

  • Open Hello.ui
  • Open Qt C++ Signal Slot Editor view

QtSignalSlotView.png

  • Click on QtSignalPlus.png 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

QtSender.png

Signal

  • Here we will select "clicked()" signal to be sent by "exitButton"

QtSignal.png

Receiver

  • Here HelloClass is the receiver of this event handling mechanism.

QtReceiver.png

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()"

QtSlot.png


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

InitialStateEmulator.png

Hello button pressed state

HelloPressedEmulator.png


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.
282 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×