Meego Wiki
Views

Hola mundo - Desarrollo para MeeGo x86 en Linux

From MeeGo wiki
(Difference between revisions)
Jump to: navigation, search
(Instrucciones opcionales para usar un equipo real MeeGo)
Line 58: Line 58:
* Cree un nuevo proyecto (''File > New File or Project''). En la opción ''Projects'', seleccione ''Qt Gui Application'' y haga clic en ''OK''.
* Cree un nuevo proyecto (''File > New File or Project''). En la opción ''Projects'', seleccione ''Qt Gui Application'' y haga clic en ''OK''.
* Escriba '''helloworld''' para el nombre; seleccione un directorio para guardarlo (por ejemplo ''/root'' si usted trabaja como el usuario root). Haga clic en ''Next''.
* Escriba '''helloworld''' para el nombre; seleccione un directorio para guardarlo (por ejemplo ''/root'' si usted trabaja como el usuario root). Haga clic en ''Next''.
-
* Accept the defaults in the ''Class Information'' dialog box and click ''Next''.
+
* Acepte las configuraciones por defecto en el cuadro de ''Class Information'' y haga clic en siguiente ''Next''.
-
* In the ''Project Management'' dialog box, click ''Finish''.
+
* En el cuadro ''Project Management'', haga clic a ''Finish''.
Luego escribimos algo de codigo:
Luego escribimos algo de codigo:
Line 87: Line 87:
En este momento, ya tenemos todo listo para ejecutar la aplicación.
En este momento, ya tenemos todo listo para ejecutar la aplicación.
-
Desde el Qt Creator, haga clic en la big green arrow (bottom-left corner) to run the application. This will build it first (using the Qt Version you set up) then run it on display ''':2''' (inside the Xephyr simulated MeeGo desktop).
+
Desde el Qt Creator, haga clic sobre la el boton de ejecutar (flecha verde en la parte inferior izquierda) para ejecutar la aplicación. Esto la construirá utilizando la version de Qt que configuró, y luego la ejecutara en el display ''':2''' (dentro del escritorio MeeGo simulado en Xephyr).
-
In the Simulator, you might need to click on the MyZone icon (the house icon) to reveal the application running behind it:
+
En el simulador, puede ser necesario hacer clic en el icono MyZone (icono de casa) para mostrar la aplicación que esta corriendo:
[[File:Simulator_running_meego_app.png]]
[[File:Simulator_running_meego_app.png]]
Line 95: Line 95:
=== Depure la aplicación dentro del simulador ===
=== Depure la aplicación dentro del simulador ===
-
This means running the application from Qt Creator, but with debugging turned on, so you can watch the state of the application while it's running under Xephyr.
+
Esto quiere decir, ejecutar la aplicación desde Qt Creator, pero con las opciones de depuración activadas, para poder observer el estado de la aplicación mientras corre bajo Xephyr.
In the previous sections, we built the debugging helper for the version of Qt we're using. This needs to be done first, otherwise you can't debug the application.
In the previous sections, we built the debugging helper for the version of Qt we're using. This needs to be done first, otherwise you can't debug the application.

Revision as of 21:23, 29 July 2010


Contents

Introducción

Este tutorial es una introducción para desarrollo de dispositivos MeeGo x86 en Linux. Se explica el flujo de trabajo basico para el desarrollo de aplicaciones, enfocandose en como trabajar conjuntamente las herramientas incluidas en el SDK.

No se entra en detalles sobre Qt, las APIs de MeeGo, o como hacer que una aplicación se integre en el entorno de MeeGo..

Como hacerlo (versión corta)

  • Descargue e instale la SDK MeeGo
  • Entre al entorno SDK MeeGo
  • Inicie el simulador
  • Inicie el Qt Creator
  • Use Qt Creator para crear un proyecto, configurelo para que use la variable de entorno DISPLAY apropiada para el simulador
  • Compile el proyecto usando las librerias Qt del SDK
  • Inicie la aplicación en el simulador
  • Depure la aplicación dentro del simulador

Si usted tiene un equipo con MeeGo:

  • Prepare el equipo
  • Inicie la aplicación en el equipo
  • Depure la aplicación en el equipo

Como hacerlo (versión larga)

Instalar el SDK MeeGo en su equipo con Linux

Vea Getting started with the MeeGo SDK for Linux para más instrucciones.

Entre al entorno chroot MeeGo

Vea estas instrucciones.

Ejecute el simulador

Con todo instalado, usted deberia poder ahora ejecutar el simulador desde el entorno de MeeGo.

Construya el proyecto con Qt Creator

Deje el guión startmeego ejecutandose, e inicie Qt Creator asi:

qtcreator &

Esto ejecuta Qt Creator en la maquina host (no dentro de Xephyr):

Simulator QtCreator splash.png

Para configurar el proyecto:

  • Cree un nuevo proyecto (File > New File or Project). En la opción Projects, seleccione Qt Gui Application y haga clic en OK.
  • Escriba helloworld para el nombre; seleccione un directorio para guardarlo (por ejemplo /root si usted trabaja como el usuario root). Haga clic en Next.
  • Acepte las configuraciones por defecto en el cuadro de Class Information y haga clic en siguiente Next.
  • En el cuadro Project Management, haga clic a Finish.

Luego escribimos algo de codigo:

  • Abra la carpeta Forms y luego haga doble clic en mainwindow.ui para abrir el editor gráfico de formularios.
  • Arrastre una etiqueta desde la lista de componentes a mano izquierda del editor de formularios y arrastrelo en el area de edición.
  • Cambie el texto por algo más («Hola mundo» podría servir).
  • Ponga cualquier otra cosa que le parezca atractiva en el formulario.

Y configuramos el proyecto:

  • Haga clic en el icono Projects en la parte izquierda de la ventana de Qt Creator.
  • Configure la versión de Qt:
    • En el menú Build Settings > General, haga clic al boton More. Esto le mostrará la versión de Qt que será usada para compilar y construir el proyecto.
    • Haga clic en el boton Manage que esta al lado de Qt Version. Esto le mostrara el panel de Qt Versions:
      Simulator QtCreator qt versions.png
    • Seleccione Qt in PATH.
    • Haga clic en Rebuild para configurar el Debugging Helper de esta versión de Qt.
    • Clic enOK para guardar sus cambios.
  • Asegurese de que Qt Version esta configurado como Default Qt Version (Qt in PATH).
  • Luego, configure el entorno de ejecución para que use el simulador para mostrar la aplicación cuando se este ejecutando:
    • Haga clic en la pestaña Run Settings.
    • Clic en el boton More dentro de Run Environment.
    • Doble clic en el campo de texto junto a Display; y cambie :0.0 a :2. Esto le dice a Qt Creator que ejecute las aplicaciónes en el display número :2, el cual es usado por Xephyr.

Ejecute la aplicación dentro del simulador

En este momento, ya tenemos todo listo para ejecutar la aplicación.

Desde el Qt Creator, haga clic sobre la el boton de ejecutar (flecha verde en la parte inferior izquierda) para ejecutar la aplicación. Esto la construirá utilizando la version de Qt que configuró, y luego la ejecutara en el display :2 (dentro del escritorio MeeGo simulado en Xephyr).

En el simulador, puede ser necesario hacer clic en el icono MyZone (icono de casa) para mostrar la aplicación que esta corriendo:

Simulator running meego app.png

Depure la aplicación dentro del simulador

Esto quiere decir, ejecutar la aplicación desde Qt Creator, pero con las opciones de depuración activadas, para poder observer el estado de la aplicación mientras corre bajo Xephyr.

In the previous sections, we built the debugging helper for the version of Qt we're using. This needs to be done first, otherwise you can't debug the application.

To put Qt Creator into debug mode, click on the bug icon in the left-hand toolbar. This adds some extra panels to the window which are used to show the stack, watch expressions etc..

Next, you need something to debug. I added a Push Button to the form:

QtCreator form with push button.png

Then added a click handler for it, so that when the button is clicked, a message string is assigned into a variable then output to the console. The code looks like this:

/* file: Headers/mainwindow.h */
#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow {
    Q_OBJECT
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

protected:
    void changeEvent(QEvent *e);

private:
    Ui::MainWindow *ui;

private slots:
    void on_pushButton_clicked();
};

#endif // MAINWINDOW_H
/* file: Sources/mainwindow.cpp */
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QString>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::on_pushButton_clicked()
{
    QString message;
    message = "I have been well and truly clicked";
    qDebug() << message;
}

Most of this is boilerplate generated when I started the project, but the MainWindow::on_pushButton_clicked method is mine. Notice how it also needs to be defined as a private slot in the header file.

Add a breakpoint next to the line where you want the debugger to break by clicking in the editor margin. It looks like this:

QtCreator set breakpoint.png

(See the red circle on line 34 after message is initialized.)

To run the application in debug mode, click on the green arrow with a bug overlaid on it (bottom left). This starts the application inside Xephyr:

QtCreator app with button.png

Now, click on the button. The program should pause at the breakpoint. Switch back to Qt Creator and look at the debug panels:

QtCreator paused at breakpoint.png

Notice how the Locals and Watchers tab reports the message variable set to "I have been well and truly clicked".

For more information about using Qt Creator in debug mode, see [1].

Instrucciones opcionales para usar un equipo real MeeGo

Si usted tiene disponible un equipo con MeeGo, tambien es posible ejecutar y depurar sus aplicaciones en el usando Qt Creator.

Prepare el equipo

El equipo requiere cierta configuración y paquetes extras antes de que pueda desplegar la aplicacion desde Qt Creator. Instalelos desde la linea de comandos como se explica:

  1. El despliegue de aplicaciones desde Qt Creator a un equipo utiliza SSH para copiar los archivos, será necesario instalar el servidor de OpenSSH en el equipo:
    sudo zypper install openssh-server

    Para iniciar el servicio manualmente (solo tiene que hacer esto justo despues de instalarlo, de lo contrario, solo estará disponible hasta que reinicie el equipo):

    sudo /etc/init.d/sshd start

    To add it to the init sequence so it starts at boot time:

    sudo chkconfig --add sshd
  2. Si usted desea depurar aplicaciones remotamente, será necesario instalar gdbserver en el equipo:
    sudo zypper install gdb-gdbserver

Ejecute la aplicación en el equipo

Dentro de Qt Creator (aún corriendo dentro del chroot):

  1. With a project selected, click on the Projects icon to show the project configuration tabs.
  2. Select the Run Settings tab.
  3. Click on the Add drop-down and select testapp on MeeGo device (testapp will be set to the name you gave your project).
  4. Click on the Manage device configurations link to display the MeeGo Device Configurations dialog.
  5. Click on the Add button (top-right) and complete the fields so they resemble the screenshot below:
    File:QtCreator configure meego device.png
    You'll need to set Host Name to the IP address or domain name of the netbook, and enter the User Name and Password you used when you set up the netbook. The other options can be left at their defaults.
  6. Click on the Test button to check the connection. If it's configured correctly, you should see a message like the one in the screenshot above ("Device configuration successful").
  7. Click on OK to save your changes. This returns you to the Run Settings tab.
  8. Select the new MeeGo netbook option from the Device Configuration drop-down.

Once you've completed this, you should be able to deploy and run the application on the netbook:

  1. At the bottom-left of the Qt Creator window is a panel for selecting the build and run environments:
    QtCreator run on device.png
    Click on the computer monitor icon, then use the arrows to select testapp on MeeGo device from the Run drop-down. The Build drop-down can be left at Debug.
  2. Click on the green arrow (the normal run arrow) to deploy the application and run it. This copies the application binary to the home folder of the user you specified in the SSH settings and runs it.
    If you can't see the application, it may be because it hasn't been given focus. You can use the zones icon in the toolbar to show the running application and select it.

Here's an example of what the application looks like running on a netbook:

Qt app running on netbook.png

Depurar la aplicación en el equipo

This works almost the same on a remote device as it does inside the Simulator.

  1. Configure the remote device as explained above.
  2. In Qt Creator, click on the Target settings (bottom left with a monitor icon). Ensure you have Build set to Debug and Run set to testapp on MeeGo device (the remote device).
  3. Click on the green arrow overlaid with a bug to start the application remotely in debug mode.

If you used the same code as above, try clicking on the Click me button in the application (running on the netbook). The application should pause at the breakpoint; and in Qt Creator, the message variable should then be visible in the Locals and Watchers tab, set to "I have been well and truly clicked". (No screenshot this time, as Qt Creator looks the same as it does for local debugging.)

Ver esta pagina en otros idiomas

Personal tools