加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > Linux嵌入式 > Megoo

Linux上的 MeeGo x86 开发

时间:2010-09-28 10:47:37  来源:  作者:

介绍

这个教程介绍了Linux下的 MeeGo x86 开发。教程解说了基本的开发流程,重点介绍了如何使用SDK附带的那些工具。

教程不会涉及一些开发细节,例如 Qt 和 MeeGo 的 API、或是如何将程序整合到 MeeGo 环境中。

如何开发 (简要说明)

  • 获取并安装 MeeGo SDK
  • 进入 MeeGo SDK 环境
  • 启动模拟器
  • 启动 Qt Creator
  • 使用 Qt Creator 创建一个项目, 配置项目的 DISPLAY 环境变量,让项目能够在模拟器中运行
  • 使用 SDK 的 Qt 库编译项目。
  • 在模拟器中运行程序
  • 在模拟器中为程序 Debug

如果你有一台真实的 MeeGo 设备:

  • 准备设备
  • 在设备上运行程序
  • 在设备上为程序 Debug

如何开发 (详细说明)

在你的机器上安装 MeeGo SDK

请参阅 在 Linux 上使用 MeeGo SDK 的介绍。

进入 MeeGo chroot 环境

请参阅 这个介绍

运行模拟器

把所有东西安装配置完成后,你应该可以在 MeeGo chroot 环境中 运行模拟器 了。

使用 Qt Creator 创建项目

让 startmeego 脚本继续运行,然后启动 Qt Creator :

qtcreator &

这会在 host 上运行 Qt Creator (而不是在 Xephyr 里):

File:Simulator_QtCreator_splash.png

然后,配置一个新项目:

  • 创建一个新项目(File > New File or Project)。 在 Projects 对话框中, 选择 Qt Gui Application ,然后点击 OK
  • 输入 helloworld 作为项目名称,选择一个保存项目的目录 (例如,如果你使用 root 账户工作的话,可以选择 /root )。 然后点击 Next
  • 保持 Class Information 对话框的默认配置,然后点击 Next
  • Project Management 对话框里,点击 Finish

输入一些代码:

  • 打开 Forms 目录,双击 mainwindow.ui 打开图形窗体编辑器。
  • 从窗体编辑器左边的组件列表里,拖出一个 label ,放到编辑中的窗体上。
  • 修改 label 的文本( "Hello world" 是个不错的选择 )。
  • 再拽几个你喜欢的东西上去。

然后配置项目:

  • 点击 Qt Creator 窗口左边的 Projects 图标。
  • 配置 Qt 版本:
    • Build Settings > General 栏里,点击 More 按钮。这会显示当前项目中使用的 Qt 库版本。
    • 点击 Qt Version 标签边上的 Manage 按钮,这会显示 Qt Versions 面板:
      File:simulator_QtCreator_qt_versions.png
    • 选中 Qt in PATH 项目。
    • 点击 Rebuild 按钮,创建当前 Qt 版本使用的 Debugging Helper
    • 点击 OK 保存设置。
  • 确认 Qt Version 的设置,应该是 Default Qt Version (Qt in PATH)
  • 然后,配置运行环境,用模拟器来显示运行的程序:
    • 点击 Run Settings 标签。
    • 点击 Run Environment 下面的 More 按钮。
    • 双击 Display 环境变量边上的文本区,将 :0.0 改为 :2 。这会让 Qt Creator 使用 :2 号显示区域来运行程序,也就是在 Xephyr 中运行。

在模拟器中运行程序

现在你已经做好了运行程序的准备。

在 Qt Creator 里,点击左下角那个大大的绿色箭头,就可以运行程序。在第一次运行时,这会编译整个项目(使用你设置的 Qt 库版本),然后在 :2 号 display (也就是 Xephyr 里的 MeeGo 模拟器)上显示程序。

在模拟器里,程序可能会在后台运行,不会直接显示在屏幕上。这时你可以需要点击 MyZone 图标激活程序:

File:Simulator_running_meego_app.png

在模拟器中为程序 Debug

在 Qt Creator 里启动程序后,如果你激活了 Debug 模式,你就可以监视这个程序的运行状态。

在之前的 小节 里,我们已经为当前版本的 Qt 库创建了 debugging helper 。这必须预先做好,不然你无法调试程序。

点击左边工具栏中的 bug 图标,这会激活 Qt Creator 的 Debug 模式。这会在窗口里增加一个面板,以显示运行栈、变量和表达式的值、以及其他有用的信息。

然后,你需要一些 Bug 好进行 debug。我在程序窗体里添加了一个 Push Button

File:QtCreator_form_with_push_button.png

然后为这个按钮添加了点击事件。当点击这个按钮时,一个字符串变量将会被打印到控制台上。代码是这样的:

/* 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;
}

大部分代码继承自原本的项目,只有 MainWindow::on_pushButton_clicked 这个方法是我自己添加的。需要注意的是,我还在头文件里定义了一个私有的槽。

译者注:信号和槽是 Qt 里的概念,请参考介绍 Qt 的文章。

然后在编辑器里,在你想要 debug 的语句左边点击一下,添加一个断点。看起来像是这样:

File:QtCreator_set_breakpoint.png

(注意 34 行左边的那个红色圆圈)

然后点击那个带着 bug 标志的绿色箭头(在左下角),这会以 Debug 模式启动程序。程序将会显示在模拟器中:

File:QtCreator_app_with_button.png

现在,在模拟器里的程序窗口中,点击那个 Push Button ,这会在刚才设置的断点上中断程序。回到 Qt Creator 里,看下 debug 面板:

File:QtCreator_paused_at_breakpoint.png

我们可以看到,在 Locals and Watchers 标签里, message 变量的值,已经被设置为 "I have been well and truly clicked" 了。

如果你需要 Qt Creator 的 Debug 模式的更多细节,请参阅 [1]

在真实的 MeeGo 设备上进行开发

如果你有一个安装了 MeeGo 系统的设备,你同样可以使用 Qt Creator 来创建和调试程序。

准备设备

使用 Qt Creator 为 MeeGo 设备进行开发前,你需要在设备上安装一些额外的软件包,并进行一些设置。你可以按照以下步骤,在终端下进行设置:

  1. 在 MeeGo 设备上部署 Qt Creator 开发环境,需要使用 SSH 。所以,先安装 OpenSSH server :
    sudo zypper install openssh-server

    然后执行下面命令(在安装完毕后执行, 否则需要等到重启设备后,才可以使用 ssh ):

    sudo /etc/init.d/sshd start

    将这个增加到自启动中,这样在设备启动时,就可以自动启动 sshd 了:

    sudo chkconfig --add sshd
  2. 如果你需要远程调试程序, 那你还需要安装 gdbserver
    sudo zypper install gdb-gdbserver

Run the application on the device

In Qt Creator (still running from the 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:
    File: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:

File:Qt_app_running_on_netbook.png

Debug the application on the device

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

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
相关文章
    无相关信息
栏目更新
栏目热门