(→Prepare the remote device) |
(→Run the application on the device) |
||
| Line 182: | Line 182: | ||
| - | <li>Select the | + | <li>Select the option corresponding to the device from the ''Device Configuration'' drop-down.</li> |
</ol> | </ol> | ||
| - | Once you've completed this, you should be able to deploy and run the application on the | + | Once you've completed this, you should be able to deploy and run the application on the device: |
<ol> | <ol> | ||
This is a very rough working draft, in progress (2010-10-25); most of the screenshots are wrong
This is a brief introduction to debugging Qt applications running on a remote MeeGo device, using Qt Creator. The instructions will work with any kind of remote MeeGo device, real or emulated.
Contents |
You will need gdb to be installed before you can do any debugging with Qt Creator. On Linux, use the package manager to install it; for example, on Fedora:
sudo yum install gdb
On MeeGo (useful if you're using Qt Creator from a chroot):
zypper install gdb
Start Qt Creator (meego-sdk-qt-creator) and setup a project:
Next write some code:
mainwindow.ui to open it in the graphical forms editor.
First, ensure that debugging is enabled for the version of Qt in use:
Next, you need something to debug. For example, add a Push Button to the form:
Then add 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();
private:
Ui::MainWindow *ui;
// our new handler
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::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 22 after message is initialized.)
To put Qt Creator into debug mode, click on Debug/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 to change the configuration, so that Qt with debugging enabled is used to run the project.
???
To run the application in debug mode, click on the green arrow with a bug overlaid on it (bottom left). This starts the application on the local machine:
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 http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging.html.
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:
Note: If you are using N900 for debugging, installing OpenSSH or gdbserver is not required.
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:
Once you've completed this, you should be able to deploy and run the application on the device:

Here's an example of what the application looks like running on a netbook:
Debugging on the remote device is as simple as debugging locally.
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.)