(→Build the project with Qt Creator) |
|||
| (24 intermediate revisions not shown) | |||
| Line 2: | Line 2: | ||
[[Category:meego-1.0]] | [[Category:meego-1.0]] | ||
[[Category:tutorial]] | [[Category:tutorial]] | ||
| - | |||
[[Category:netbook]] | [[Category:netbook]] | ||
[[Category:c++]] | [[Category:c++]] | ||
| Line 8: | Line 7: | ||
[[Category:linux]] | [[Category:linux]] | ||
| - | + | == Introduction == | |
| - | + | This tutorial introduces developing for MeeGo x86 devices on Linux. It explains the basic application development workflow, focusing on how the tools in the SDK work together. | |
| - | + | It does not go into detail about Qt, the MeeGo APIs, or how to make an application integrate with the MeeGo environment. | |
| - | = How to do it (the short version) = | + | == How to do it (the short version) == |
* Get and install the MeeGo SDK | * Get and install the MeeGo SDK | ||
| Line 31: | Line 30: | ||
* Debug the application on the device | * Debug the application on the device | ||
| - | = How to do it (the longer version) = | + | == How to do it (the longer version) == |
| - | == Install the MeeGo SDK on your Linux machine == | + | === Install the MeeGo SDK on your Linux machine === |
| - | See [[Getting started with the MeeGo SDK for Linux]] for | + | See [[SDK/Docs/1.0/Getting started with the MeeGo SDK for Linux]] for instructions. |
| - | == Enter the MeeGo | + | === Enter the MeeGo chroot environment === |
| - | See [[Getting_started_with_the_MeeGo_SDK_for_Linux# | + | See [[SDK/Docs/1.0/Getting_started_with_the_MeeGo_SDK_for_Linux#Enter the MeeGo chroot environment|these instructions]]. |
| - | == Run the Simulator == | + | === Run the Simulator === |
| - | With everything installed, you should now be able to [[Getting_started_with_the_MeeGo_SDK_for_Linux#Run_the_Simulator|run the Simulator]]. | + | With everything installed, you should now be able to [[SDK/Docs/1.0/Getting_started_with_the_MeeGo_SDK_for_Linux#Run_the_Simulator|run the Simulator]] from the MeeGo environment. |
| - | == Build the project with Qt Creator == | + | === Build the project with Qt Creator === |
| - | + | Leave the startmeego script running, and start Qt Creator with: | |
qtcreator & | qtcreator & | ||
| Line 58: | Line 57: | ||
* Create a new project (''File > New File or Project''). Under ''Projects'', select ''Qt Gui Application'' and click ''OK''. | * Create a new project (''File > New File or Project''). Under ''Projects'', select ''Qt Gui Application'' and click ''OK''. | ||
| - | * Enter '''helloworld''' for the name; choose a directory to save it to. Click on ''Next''. | + | * Enter '''helloworld''' for the name; choose a directory to save it to (such as ''/root'' if you're working as the root user). Click on ''Next''. |
* Accept the defaults in the ''Class Information'' dialog box and click ''Next''. | * Accept the defaults in the ''Class Information'' dialog box and click ''Next''. | ||
* In the ''Project Management'' dialog box, click ''Finish''. | * In the ''Project Management'' dialog box, click ''Finish''. | ||
| Line 80: | Line 79: | ||
* Make sure that the ''Qt Version'' is now set to '''Default Qt Version (Qt in PATH)'''. | * Make sure that the ''Qt Version'' is now set to '''Default Qt Version (Qt in PATH)'''. | ||
* Next, configure the run environment to use the Simulator to display the application when it's running: | * Next, configure the run environment to use the Simulator to display the application when it's running: | ||
| - | ** | + | ** Click on the ''Run Settings'' tab. |
| + | ** Click on the ''More'' button under ''Run Environment''. | ||
** Double-click in the text entry next to the ''Display'' variable; change ''':0.0''' to ''':2'''. This tells Qt Creator to run the application on display number :2, the one which Xephyr is in control of. | ** Double-click in the text entry next to the ''Display'' variable; change ''':0.0''' to ''':2'''. This tells Qt Creator to run the application on display number :2, the one which Xephyr is in control of. | ||
| - | == Run the application inside the Simulator == | + | === Run the application inside the Simulator === |
Now you're all set to run the application. | Now you're all set to run the application. | ||
| + | |||
| + | First don't forget to generate the makefile (apply qmake). | ||
From inside Qt Creator, click on the 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). | From inside Qt Creator, click on the 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). | ||
| Line 93: | Line 95: | ||
[[File:Simulator_running_meego_app.png]] | [[File:Simulator_running_meego_app.png]] | ||
| - | == Debug the application inside the Simulator == | + | === Debug the application inside the Simulator === |
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. | 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. | ||
| Line 196: | Line 198: | ||
For more information about using Qt Creator in debug mode, see [http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging.html]. | For more information about using Qt Creator in debug mode, see [http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging.html]. | ||
| - | = Optional instructions for using a real MeeGo device = | + | == Optional instructions for using a real MeeGo device == |
If you have a real MeeGo device available, it's also possible to run and debug your application on it using Qt Creator. | If you have a real MeeGo device available, it's also possible to run and debug your application on it using Qt Creator. | ||
| - | == Prepare the device == | + | === Prepare the device === |
The device requires some configuration and extra packages before you can deploy from Qt Creator to it. Install them from the command line as follows: | The device requires some configuration and extra packages before you can deploy from Qt Creator to it. Install them from the command line as follows: | ||
| Line 207: | Line 209: | ||
<li> | <li> | ||
Deployment from Qt Creator to a real device uses SSH for file copying, so you need to install OpenSSH server on the netbook with: | Deployment from Qt Creator to a real device uses SSH for file copying, so you need to install OpenSSH server on the netbook with: | ||
| - | <pre>sudo | + | <pre>sudo zypper install openssh-server</pre> |
To start it manually (you'll need to do this just after you've installed it, otherwise it won't be available until you reboot): | To start it manually (you'll need to do this just after you've installed it, otherwise it won't be available until you reboot): | ||
<pre>sudo /etc/init.d/sshd start</pre> | <pre>sudo /etc/init.d/sshd start</pre> | ||
| Line 215: | Line 217: | ||
<li> | <li> | ||
If you want to debug applications remotely, you need to install ''gdbserver'' on the netbook: | If you want to debug applications remotely, you need to install ''gdbserver'' on the netbook: | ||
| - | <pre>sudo | + | <pre>sudo zypper install gdb-gdbserver</pre> |
</li> | </li> | ||
</ol> | </ol> | ||
| - | == Run the application on the device == | + | === Run the application on the device === |
In Qt Creator (still running from the chroot): | In Qt Creator (still running from the chroot): | ||
| Line 254: | Line 256: | ||
[[File:Qt_app_running_on_netbook.png]] | [[File:Qt_app_running_on_netbook.png]] | ||
| - | == Debug the application on the device == | + | === Debug the application on the device === |
This works almost the same on a remote device as it does [[#Debug the application inside the Simulator | inside the Simulator]]. | This works almost the same on a remote device as it does [[#Debug the application inside the Simulator | inside the Simulator]]. | ||
| Line 262: | Line 264: | ||
# Click on the green arrow overlaid with a bug to start the application remotely in debug mode. | # 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 | + | 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 because Qt Creator looks the same as it does for local debugging.) |
| + | |||
| + | == Another language version of this page == | ||
| + | |||
| + | * [[Hello World - Linux上的 MeeGo x86 开发|Simplified Chinese - 简体中文]] | ||
| + | * [[Hola mundo - Desarrollo para MeeGo x86 en Linux|Spanish - Español]] | ||
Contents |
This tutorial introduces developing for MeeGo x86 devices on Linux. It explains the basic application development workflow, focusing on how the tools in the SDK work together.
It does not go into detail about Qt, the MeeGo APIs, or how to make an application integrate with the MeeGo environment.
If you've got a MeeGo device:
See SDK/Docs/1.0/Getting started with the MeeGo SDK for Linux for instructions.
See these instructions.
With everything installed, you should now be able to run the Simulator from the MeeGo environment.
Leave the startmeego script running, and start Qt Creator with:
qtcreator &
This runs Qt Creator on the host (not inside Xephyr):
To setup the project:
Next write some code:
Then configure the project:
Now you're all set to run the application.
First don't forget to generate the makefile (apply qmake).
From inside Qt Creator, click on the 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).
In the Simulator, you might need to click on the MyZone icon (the house icon) to reveal the application running behind it:
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.
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:
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:
(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:
Now, click on the button. The program should pause at the breakpoint. Switch back to Qt Creator and look at the debug panels:
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].
If you have a real MeeGo device available, it's also possible to run and debug your application on it using Qt Creator.
The device requires some configuration and extra packages before you can deploy from Qt Creator to it. Install them from the command line as follows:
sudo zypper install openssh-server
To start it manually (you'll need to do this just after you've installed it, otherwise it won't be available until you reboot):
sudo /etc/init.d/sshd start
To add it to the init sequence so it starts at boot time:
sudo chkconfig --add sshd
sudo zypper install gdb-gdbserver
In Qt Creator (still running from the chroot):
Once you've completed this, you should be able to deploy and run the application on the netbook:

Here's an example of what the application looks like running on a netbook:
This works almost the same on a remote device as it does inside the Simulator.
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 because Qt Creator looks the same as it does for local debugging.)