(→Prerequisites) |
(→Prepare the host) |
||
| (10 intermediate revisions not shown) | |||
| Line 2: | Line 2: | ||
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. | 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. | ||
| - | |||
| - | |||
== Prerequisites == | == Prerequisites == | ||
| - | You will need | + | You will need: |
| - | + | * Qt Creator set up for your operating system | |
| + | * A new project, configured to deploy to a MeeGo device (real or emulated) | ||
| - | + | [[SDK/Docs/1.1/Creating_Hello_World|This tutorial]] is a good place to start to get everything in place. | |
| - | + | === Prepare the host === | |
| - | You | + | 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 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 41: | 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 | + | # 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. |
| - | + | === Set a breakpoint === | |
| - | [[File: | + | 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 107: | Line 102: | ||
</pre> | </pre> | ||
| - | Most of this is boilerplate generated | + | 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 122: | 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. | ||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
| - | |||
== 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 | + | 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: | ||
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:
This tutorial is a good place to start to get everything in place.
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.
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
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 (defined in mainwindow.ui):
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:
(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 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:
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.