Meego Wiki
Views

SDK/Docs/1.1/Debugging with Qt Creator

From MeeGo wiki
< SDK | Docs | 1.1(Difference between revisions)
Jump to: navigation, search
(Prepare the remote device)
(Prepare the host)
 
(18 intermediate revisions not shown)
Line 5: Line 5:
== Prerequisites ==
== Prerequisites ==
-
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:
+
You will need:
-
sudo yum install gdb
+
* Qt Creator set up for your operating system
 +
* A new project, configured to deploy to a MeeGo device (real or emulated)
-
On MeeGo (useful if you're using Qt Creator from a chroot):
+
[[SDK/Docs/1.1/Creating_Hello_World|This tutorial]] is a good place to start to get everything in place.
-
zypper install gdb
+
=== Prepare the host ===
-
== Create a project with Qt Creator ==
+
You will need '''gdb''' to be installed on the host 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
-
Start Qt Creator (<code>meego-sdk-qt-creator</code>) and setup a project:
+
On Windows, it is installed with the SDK automatically.
-
# Create a new project (''File > New File or Project''). Under ''Projects'', select ''Qt C++ Project'' then ''Mobile Qt Application''. Click ''Choose...''.
+
=== Prepare the device ===
-
# In the ''Location'' section, enter '''helloworld''' for the name; choose a directory to save it to. Click on ''Next &gt;''.
+
-
# In the ''Qt Versions'' section, make sure the '''MeeGo 4.7.0''' version of Qt is selected and click ''Next &gt;''.
+
-
# In the ''Details'' section, accept the defaults and click ''Next &gt;''.
+
-
# In the ''Project Management'' section, click ''Finish''.
+
-
Next write some code:
+
You will need '''gdb-gdbserver''' to be installed on the device. Either on the real device or in the emulator image, install it with:
-
# Open the ''Forms'' folder and double-click <code>mainwindow.ui</code> to open it in the graphical forms editor.
+
sudo zypper in gdb-gdbserver
-
# Drag a label from the list of widgets on the left-hand side of the forms editor (under ''Display Widgets'') and drop it into the editable area.
+
-
# Change the text to something else ("Hello world" works well).
+
-
== Configure the project for debugging ==
+
=== Configure the Qt Creator project for debugging ===
First, ensure that debugging is enabled for the version of Qt in use:
First, ensure that debugging is enabled for the version of Qt in use:
Line 35: Line 34:
# Click on the ''Projects'' button in the left-hand panel.
# Click on the ''Projects'' button in the left-hand panel.
# Under ''General'', click on the ''Manage'' button next to ''Qt Version''.
# Under ''General'', click on the ''Manage'' button next to ''Qt Version''.
-
# Select the Qt version you are using: use the MeeGo Qt version for your particular target (in this case, '''MeeGo 4.7.0''').
+
# Select the Qt version you are using: use the MeeGo Qt version for your particular target (in this case, '''MeeGo sysroot''').
-
# Click on the ''Rebuild'' button next to ''Debugging helpers'' (near the bottom of the dialog box). This builds the debugging helper for this version of Qt.
+
# Click on the ''Rebuild'' button next to ''Debugging helpers'' (near the bottom of the dialog box). This builds the debugging helper for this version of Qt. You should see a green tick under the ''Debugging'' column for that Qt version.
-
Next, you need something to debug. For example, add a ''Push Button'' to the form:
+
=== Set a breakpoint ===
-
[[File:sdk-docs-QtCreator-form-with-push-button.png|800px]]
+
Next, you need something to debug. For example, add a ''Push Button'' to the form (defined in <code>mainwindow.ui</code>):
 +
 
 +
[[File:Sdk-docs-QtCreator-form-with-push-button.png|800px]]
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:
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:
Line 101: Line 102:
</pre>
</pre>
-
Most of this is boilerplate generated when I started the project, but the <code>MainWindow::on_pushButton_clicked</code> method is mine. Notice how it also needs to be defined as a private slot in the header file.
+
Most of this is boilerplate generated the project was started, but the <code>MainWindow::on_pushButton_clicked</code> method is new. 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:
Add a breakpoint next to the line where you want the debugger to break by clicking in the editor margin. It looks like this:
Line 116: Line 117:
# Under ''Build Settings'', select '''Debug''' from the drop-down box next to ''Edit build configuration''.
# Under ''Build Settings'', select '''Debug''' from the drop-down box next to ''Edit build configuration''.
# From the ''Build'' menu, select ''Rebuild all''. This recompiles the project using the debug-enabled Qt.
# From the ''Build'' menu, select ''Rebuild all''. This recompiles the project using the debug-enabled Qt.
-
 
-
<!--
 
-
== Setup/start emulator ==
 
-
 
-
???this is currently a manual step for Linux host, but on Windows Qt Creator there is a button to start the emulator; not sure why there's a discrepancy
 
-
-->
 
-
 
-
== Prepare the remote 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:
 
-
 
-
'''Note''': If you are using N900 for debugging, OpenSSH and gdbserver are included in the image. Thus, you do not have to install them separately.
 
-
 
-
<ol>
 
-
<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:
 
-
<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):
 
-
<pre>sudo /etc/init.d/sshd start</pre>
 
-
To add it to the init sequence so it starts at boot time:
 
-
<pre>sudo chkconfig --add sshd</pre>
 
-
</li>
 
-
<li>
 
-
If you want to debug applications remotely, you need to install '''gdbserver''' on the remote device:
 
-
<pre>sudo zypper install gdb-gdbserver</pre>
 
-
</li>
 
-
<li>The root user needs to be able to access the X server on the remote device. Configure this with:
 
-
<pre>xhost +SI:localuser:root</pre>
 
-
</li>
 
-
</ol>
 
-
 
-
== Run the application on the device ==
 
-
 
-
In this example, the device is a MeeGo netbook, but the same instructions are applicable for other MeeGo devices (for example, a handset).
 
-
 
-
In Qt Creator:
 
-
 
-
<ol>
 
-
<li>From the ''Tools'' menu, select ''Options''.</li>
 
-
<li>Select the ''Projects'' section.</li>
 
-
<li>Click on the ''MeeGo Device Configurations'' tab.</li>
 
-
<li>Click on the ''Add'' button to start adding a new configuration.</li>
 
-
<li>Click on the ''Add'' button (top-right) and complete the fields so they resemble the screenshot below:<br/>
 
-
[[File:sdk-docs-QtCreator-configure-meego-device.png|800px]]<br/>
 
-
You'll need to set ''Host Name'' to the IP address or domain name of the device, and enter '''root''' as the ''User Name'', with the ''Password'' you used when you set up the device. (The root user is required to allow the RPM installation to work.) The other options can be left at their defaults.</li>
 
-
<li>Click on the ''Test'' button to check the connection. If it's configured correctly, you should see a message like this:<br/>
 
-
[[File:sdk-docs-QtCreator-device-configuration-test.png]]
 
-
</li>
 
-
<li>Click ''OK'' to save your changes.</li>
 
-
<li>In the ''Projects'' section again, select ''Run'' settings. Change the name from '''New MeeGo Run Configuration''' to '''MeeGo device'''. Then select '''MeeGo device''' as the device configuration.</li>
 
-
</ol>
 
-
 
-
Once you've completed this, you should be able to deploy and run the application on the device:
 
-
 
-
<ol>
 
-
<li>At the bottom-left of the Qt Creator window is a panel for selecting the build and run environments:<br/>
 
-
[[File:sdk-docs-QtCreator-build-run-target-selector.png]]<br/>
 
-
Click on the handset icon (the top icon), then use the arrows to select '''helloworld on MeeGo device''' from the ''Run'' drop-down. The ''Build'' drop-down can be left at '''Debug'''.
 
-
</li>
 
-
<li>
 
-
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.<br/>
 
-
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.
 
-
</li>
 
-
</ol>
 
-
 
-
Here's an example of what the application looks like running on a netbook:
 
-
 
-
[[File:sdk-docs-Qt-app-running-on-netbook.png]]
 
== Debug the application on the device ==
== Debug the application on the device ==
-
To run the application in debug mode, click on the green arrow with a bug overlaid on it (bottom left). This deploys the application to the remote device and starts it, as above; however, it also enables you to debug the remote application inside Qt Creator.
+
To run the application in debug mode, click on the green arrow with a bug overlaid on it (bottom left). This deploys the application to the remote device and starts it, [[SDK/Docs/1.1/Creating_Hello_World#Running the Hello World|as in this tutorial]]; however, it also enables you to debug the remote application inside Qt Creator.
Now, click on the ''Click me!'' button in the application running on the device. The program should pause at the breakpoint. Switch back to Qt Creator and look at the debug panels:
Now, click on the ''Click me!'' button in the application running on the device. The program should pause at the breakpoint. Switch back to Qt Creator and look at the debug panels:
Line 193: Line 126:
[[File:sdk-docs-QtCreator-paused-at-breakpoint.png|800px]]
[[File:sdk-docs-QtCreator-paused-at-breakpoint.png|800px]]
-
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".
+
The application should pause at the breakpoint; and in Qt Creator, the <code>message</code> variable should then be visible in the ''Locals and Watchers'' tab, 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.
For more information about using Qt Creator in debug mode, see http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging.html.

Latest revision as of 10:19, 2 December 2010


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

Prerequisites

You will need:

  • Qt Creator set up for your operating system
  • A new project, configured to deploy to a MeeGo device (real or emulated)

This tutorial is a good place to start to get everything in place.

Prepare the host

You will need gdb to be installed on the host 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 Windows, it is installed with the SDK automatically.

Prepare the device

You will need gdb-gdbserver to be installed on the device. Either on the real device or in the emulator image, install it with:

sudo zypper in gdb-gdbserver

Configure the Qt Creator project for debugging

First, ensure that debugging is enabled for the version of Qt in use:

  1. Click on the Projects button in the left-hand panel.
  2. Under General, click on the Manage button next to Qt Version.
  3. Select the Qt version you are using: use the MeeGo Qt version for your particular target (in this case, MeeGo sysroot).
  4. Click on the Rebuild button next to Debugging helpers (near the bottom of the dialog box). This builds the debugging helper for this version of Qt. You should see a green tick under the Debugging column for that Qt version.

Set a breakpoint

Next, you need something to debug. For example, add a Push Button to the form (defined in mainwindow.ui):

Sdk-docs-QtCreator-form-with-push-button.png

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 the project was started, but the MainWindow::on_pushButton_clicked method is new. 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:

Sdk-docs-QtCreator-set-breakpoint.png

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

  1. In the left-hand panel, click on Projects.
  2. Under Build Settings, select Debug from the drop-down box next to Edit build configuration.
  3. From the Build menu, select Rebuild all. This recompiles the project using the debug-enabled Qt.

Debug the application on the device

To run the application in debug mode, click on the green arrow with a bug overlaid on it (bottom left). This deploys the application to the remote device and starts it, as in this tutorial; however, it also enables you to debug the remote application inside Qt Creator.

Now, click on the Click me! button in the application running on the device. The program should pause at the breakpoint. Switch back to Qt Creator and look at the debug panels:

Sdk-docs-QtCreator-paused-at-breakpoint.png

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

For more information about using Qt Creator in debug mode, see http://doc.qt.nokia.com/qtcreator-snapshot/creator-debugging.html.

Personal tools