(→Configuring device access in Qt Creator) |
(→Configuring device access in Qt Creator) |
||
| Line 87: | Line 87: | ||
However, in both cases, the mode of access is the same: Qt Creator will deploy and install an RPM on the device, then run its executable. | However, in both cases, the mode of access is the same: Qt Creator will deploy and install an RPM on the device, then run its executable. | ||
| - | * [[SDK/Docs/1.1/Setting_up_N900_device#Configuring_device_access_in_Qt_Creator|N900]] | + | * [[SDK/Docs/1.1/Setting_up_N900_device#Configuring_device_access_in_Qt_Creator|N900]] |
| + | * [[SDK/Docs/1.1/Setting_up_Netbook#Configuring_device_access_in_Qt_Creator|Netbook]] | ||
* [[SDK/Docs/1.1/Configuring_QEMU_targets#Configuring_access_to_an_emulated_device_in_Qt_Creator|QEMU image]] | * [[SDK/Docs/1.1/Configuring_QEMU_targets#Configuring_access_to_an_emulated_device_in_Qt_Creator|QEMU image]] | ||
Note: This page is work-in-progress (26 Oct 2010).
This page explains how to create a Hello World application with Qt Creator and run it on a MeeGo device (real or emulated).
Contents |
To create a project:
To create a Hello World application:
For more information on the Hello World created here, see the Qt Mobility Quickstart Example.
1. In Qt Creator, select Edit mode.
2. To view your project files, open Forms, Headers, and Sources folders in Projects sidebar.
3. To create an application that uses the QSystemInfo headers to print out the system's current country code, replace the existing example code in your main.cpp file with the following example code:
#include <QApplication>
#include <QLabel>
#include <QSystemInfo>
using namespace QtMobility;
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QSystemInfo s;
QLabel *label = new QLabel(QObject::tr("hello ").append(s.currentCountryCode()));
label->show();
label->resize(100,30);
return app.exec();
}
4. Replace the corresponding lines in your .pro file with the following System Information API declaration:
CONFIG += mobility MOBILITY += systeminfo
Do not remove the existing code in the file.
5. In the File menu, select Save All.
Your application is now ready to be configured for building.
To configure your Hello World for building:
If you run your Hello World application, an .rpm package is created automatically.
If you want to create a package of your Hello World application without running it, click Build All or select Build > Build Project "<project name>".
Compile Output view shows the message "Package created." and an .rpm package file (<project name>-<project version>-<release version>.<device architecture>.rpm) has been created in the build-specific project subdirectory ("<project name>-build-meego").
The process is slightly different, depending on whether you are deploying to a real device or an emulated one.
However, in both cases, the mode of access is the same: Qt Creator will deploy and install an RPM on the device, then run its executable.
To run your Hello World on your device:
Here's an example of the application running on a netbook:
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
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: Sources/main.cpp */
#include <QtGui/QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
/* 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 above; 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.