Meego Wiki
Views

SDK/Docs/1.1/Creating Hello World

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
(Creating a Hello World)
(Creating a Hello World)
Line 72: Line 72:
#: [[File:Qt Creator build settings mobility.png|frame|none|Configuring build settings in Qt Creator]]
#: [[File:Qt Creator build settings mobility.png|frame|none|Configuring build settings in Qt Creator]]
#: Your Hello World is now ready to be configured for running in QEMU or your device.
#: Your Hello World is now ready to be configured for running in QEMU or your device.
-
 
-
Draft content to be verified, reviewed and finalized for MeeGo 1.1.
 
== Packaging the Hello World ==
== Packaging the Hello World ==

Revision as of 10:14, 29 October 2010


Note: This page is work-in-progress (26 Oct 2010).

This page explains how to create a Hello World application with Qt Creator and run it on a MeeGo device (real or emulated).

Contents

Prerequisites

Creating a Hello World

To create a project:

  1. In Qt Creator, select File > New File or Project.
  2. Select Mobile Qt Application and click Choose....
    Creating your project
  3. Name your project, select where you want to save it, and click Next.
    Note: Make sure that the path to the location does not contain spaces.
    Naming your project
  4. Select MeeGo target and click Next.
    Selecting the MeeGo target
  5. Name the files that will be automatically created for your project.
    Naming classes for your project
  6. If you want to add the project to version control, do so. Otherwise click Finish.
    Adding your project to version control
Your project has now been created.

To create a Hello World application:

For more information on the Hello World created here, see the Qt Mobility Quickstart Example.

1. In Qt Creator, select Edit mode.

2. To view your project files, open Forms, Headers, and Sources folders in Projects sidebar.

3. To create an application that uses the QSystemInfo headers to print out the system's current country code, replace the existing example code in your main.cpp file with the following example code:

#include <QApplication>
#include <QLabel>
#include <QSystemInfo>
using namespace QtMobility;

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QSystemInfo s;
    QLabel *label = new QLabel(QObject::tr("hello ").append(s.currentCountryCode()));
    label->show();
    label->resize(100,30);
    return app.exec();
}

4. Replace the corresponding lines in your .pro file with the following System Information API declaration:

CONFIG += mobility
MOBILITY += systeminfo

Do not remove the existing code in the file.

5. In the File menu, select Save All.

Your application is now ready to be configured for building.

To configure your Hello World for building:

  1. Switch to Projects mode.
  2. Click Build Settings.
  3. On Edit build configuration: line, select Add > Using Qt version "MeeGo sysroot".
  4. Change Debug into MeeGo sysroot Release.
    Configuring build settings in Qt Creator
    Your Hello World is now ready to be configured for running in QEMU or your device.

Packaging the Hello World

If you run your Hello World application, an .rpm package is created automatically.

If you want to create a package of your Hello World application without running it, click Build All or select Build > Build Project "<project name>".

Compile Output view shows the message "Package created." and an .rpm package file (<project name>-<project version>-<release version>.<device architecture>.rpm) has been created in the build-specific project subdirectory ("<project name>-build-meego").

Configuring device access in Qt Creator

The process is slightly different, depending on whether you are deploying to a real device or an emulated one.

However, in both cases, the mode of access is the same: Qt Creator will deploy and install an RPM on the device, then run its executable.

Configuring access to a real device

Qt Creator configuring N900 device access usb.png

To configure device access:

  1. Open Tools > Options > Projects > MeeGo Device Configurations.
  2. In the dialog box, create a new Device Configuration by clicking on Add.
  3. Give the new Device Configuration a name in the Configuration Name text field, and add the following settings in the other test fields:
    • Device type: choose Remote device
    • Authentication type: Password
    • Host name: <device IP address> (USB port IP address 192.168.2.15 by default)
    • Ports, SSH: 22
    • Ports, Gdb Server: 10000
    Note: If this port is not free, you can select another one.
    • Connection Timeout: 30
    • User Name: root
    • Password: meego
  4. Click Apply.
  5. To test the settings, click Test.
    If successful, you'll see a dialog box with the message "Device configuration successful".
    If the message "Could not connect to host" is displayed, check your setting selections and make sure that the network is connected.
  6. Click Close and OK.

Configuring access to an emulated device

Sdk-docs-QtCreator-configuring-emulator-access.png

To configure access to an emulated device:

  1. Open Tools > Options > Projects > MeeGo Device Configurations.
  2. In the dialog box, create a new Device Configuration by clicking on Add.
  3. Give the new Device Configuration a name in the Configuration Name text field, and add the following settings in the other test fields:
    • Device type: choose MeeGo emulator
    • Authentication type: Password
    • Host name: 127.0.0.1
    • Ports, SSH: 6666
      Note that the emulator is setup with a redirect from port 6666 on localhost to the SSH port (22) of the emulated device.
    • Ports, Gdb Server: 13219 (the default)
    Note: If this port is not free, you can select another one.
    • Connection Timeout: 30
    • User Name: root
    • Password: meego
  4. Click Apply.
  5. To test the settings, ensure that the emulated device is running, then click Test.
    If successful, you'll see a dialog box with the message "Device configuration successful".
    If the message "Could not connect to host" is displayed, check your setting selections and make sure that the network is connected.
  6. Click Close and OK.

Running the Hello World

To run your Hello World on your device:

  1. Switch to Projects mode.
  2. Click Run Settings.
  3. In Device configuration drop-down menu, select the device configuration you created when configuring device access.
    Qt Creator run settings mobility.png
  4. Click Run.
    Your Hello World runs on your device.
Personal tools