Linux上简单的meego开发QT程序

Hello World - Linux上的 MeeGo x86 开发

http://blog.csdn.net/vip_dog/archive/2010/06/01/5640405.aspx 

Contents

1 介绍

2 如何开发 (简要说明)

3 如何开发 (详细说明)

3.1 在你的机器上安装 MeeGo SDK

3.2 进入 MeeGo chroot 环境

3.3 运行模拟器

3.4 使用 Qt Creator 创建项目

3.5 在模拟器中运行程序

3.6在模拟器中调试程序

4 MeeGo实体设备开发说明

4.1 配置设备

4.2在设备上运行程序

4.3 在设备上调试程序

 

1.介绍

这个教程介绍了Linux下的 MeeGo x86 开发。教程解说了基本的开发流程,重点介绍了如何使用SDK附带的那些工具。教程不会涉及一些开发细节,例如 Qt MeeGo API、或是如何将程序整合到 MeeGo 环境中。

 

2.如何开发 (简要说明)

1)        获取并安装MeeGo SDK

2)        进入MeeGo SDK 环境

3)        启动模拟器

4)        启动Qt Creator

5)        使用Qt Creator 创建一个项目, 配置项目的 DISPLAY 环境变量,让项目能够在模拟器中运行。

6)        使用SDKQt 库编译项目。

7)        在模拟器中运行程序

8)        在模拟器中为程序 Debug

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

10)     准备设备

11)     在设备上运行程序

12)     在设备上为程序 Debug

3.如何开发 (详细说明)

3.1在你的机器上安装 MeeGo SDK

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

3.2进入 MeeGo chroot 环境

请参阅 这个介绍

3.3运行模拟器

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

3.13.23.3在上一篇日志中有详细介绍)

3.4使用 Qt Creator 创建项目

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

qtcreator &

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

(缺图)

然后,配置一个新项目:

 *.创建一个新项目( 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 面板:

(缺图)

 *.选中 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 中运行。

3.5在模拟器中运行应用程序

现在开始运行应用程序)

Qt Creator中,点击左下角出绿色箭头,运行应用程序。

Qt Creator会先build程序,然后在Xephyr模拟的MeeGo桌面环境中运行程序

在模拟器中,你可能需要点击MyZone图标(房子图标)来显示运行的应用程序

(缺图)

3.6在模拟器中调试应用程序

debug调试应用程序,让你看到应用程序在模拟器中的的运行情况。在前部分内容中,已经为我们Qt版本builtdebugging helper,不然这里就不能使用debug调试程序。

 

点击bug图标(在工具条的左边)把Qt Creator设置为debug模式。在窗口上加上一些panel

接下来,为了示意调试功能,在form上加上一个Push Button

(缺图)

然后给Push Button加上了一个点击响应,以便点击Button的时候,消息字符串可以动态的在控制台上显示。代码如下:

/* file: Headers/mainwindow.h */

#ifndef MAINWINDOW_H

#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {   

class MainWindow;

}

class MainWindow : public QMainWindow

{   

Q_OBJECTpublic:   

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;

}

上面大部分代码由Qt Creator自动生成,这里只是定义了MainWindow::on_pushButton_clicked()函数,需要注意,必须在头文件中把此函数定义为私有的槽。

在需要调试的那行代码的编辑框边沿上点击,可以加上一个断点。 It looks like this:

(缺图)

点击绿色图标bug,在调试模式下运行应用程序。

(缺图)

点击button,程序停止在断点出。跳转回Qt Creator,查看debug页面。

(缺图)

注意LocalsWatchers tab如何输出消息变化为"I have been well and truly clicked"

有关Qt Creator的更多信息请查看[1] .

4. MeeGo实体设备开发说明

如果你有一个MeeGo系统的设备,你也可以用Qt Creator运行调试你在设备上的的程序。

4.1配置设备

在使用Qt Creator之前,设备需要预先进行一些配置和安装一些软件包。在如下的命令行中完成这些工作:

 1.为了可以使用SSHQt Creator中拷贝文件代码到设备中,你需要在设备(netbook)上安装OpenSSH服务:

sudo zypper install openssh-server

手动开启,否则只有重启后才会开启:

sudo /etc/init.d/sshd start

加入初始化序列以便启动时候开启SSH服务

sudo chkconfig --add sshd

2.如果你需要远程调试程序,就需要在netbook上安装gdbserver服务:

sudo zypper install gdb-gdbserver

 

4.2在设备上运行程序

仍然从chroot上启动Qt Creator

1.选择工程,点击Project图标,显示出工程的配置框。

2.选择Run Setting

3.点击Add drop-down,选择testapp

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:(缺图)(点击Add按钮(右上方),按照下图完成设置。)

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.(你需要设置Host NameIP地址,或netbook名,输入上网本的用户名和密码。其他选项保持默认。)

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").(点击Test按钮测试连接情况。如果设置没问题,你应该看到一个消息"Device configuration successful"

7.Click on OK to save your changes. This returns you to the Run Settings tab.(点击OK保存设置,返回Run Setting界面)

8.Select the new MeeGo netbook option from the Device Configuration drop-down.(从Device Configuration drop-down中选择新设置好的MeeGo上网本。)

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:(缺图)(在Qt Creator窗口的左下方,有一个按钮可以选择buildrun环境。)

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:(缺图)

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

原文地址:https://www.cnblogs.com/leaven/p/1757819.html