Qt Application Development

From ESS-WIKI
Jump to: navigation, search

We have two ways to build a Qt project: the command line mode and the gui mode. We have a description as follow:

Setup Environment in command line mode

If you want to build C, C++, Qt and other linux application, there is a magical script to use. It’s environment-setup in the $(BSP_ROOT)/cross_compiler/linux-devkit directory. To build some linux application, you just need to excute this script as follow, and then everything will be ok.

$ cd  $(BSP_ROOT)/cross_compiler/linux-devkit> 
$ source  environment-setup

After this, you can buid Qt project. For example, we have a calculator qt demo to build as follow:

$  cd  $(demo)/calculator
$  ls 
button.cpp  button.h  calculator.cpp  calculator.h  calculator.pro  main.cpp
$  qmake calculator.pro   ## Generating a makefile
$  make  	## If no error, a binary will be generated after make.

Setup Environment in gui mode

Qt Creator is a cross-platform IDE that makes application and UI development a breeze. Since time-to-market is key, the IDE includes productivity tools that speed up your development time. Before your qt developement in gui mode, a qtcreator is essential. You can download it at this link https://www.qt.io/download/. The Installation package qt-unified-linux-x64-2.0.3-1-online.run is recommended, because we have tested it on ubuntu14.04 and some previous version of qtcreator installer has some bugs on using gdb debugging.

Then, there are some steps to setup your developement environment as follow:

Start the qtcreator IDE

$ cd  $(BSP_ROOT)/cross_compiler/linux-devkit> 
$ source  environment-setup
$ cd $(your_qtcreator_install_path)/Tools/QtCreator/bin
$ ./qtcreator.sh

And the QtCreator's main window shows up. Qt1.png
Check QtCreator's version by using "Help" -> "About Qt Creator". Qt2.png


Configuring the Cross-Compiler Options

Qt Creator groups settings used for building and running projects as kits to make cross-platform and cross-configuration development easier. Each kit consists of a set of values that define one environment, such as a device, compiler, Qt version, and debugger command to use, and some metadata, such as an icon and a name for the kit. Once you have defined kits, you can select them to build and run projects.

  • Let's have a view for kits, select "Tools" -> "Options..." -> "Build & Run" -> "Kits"

Qt3.png

Device: You can connect mobile devices to the host PC to run, debug, and analyze applications on them from Qt Creator. You can connect Linux-based devices over a WLAN. You must also configure a connection between Qt Creator and the host PC in the device tab.

Compiler: Qt is supported on a variety of 32-bit and 64-bit platforms, and can usually be built on each platform with GCC, a vendor-supplied compiler, or a third party compiler. In Qt Creator, a kit specifies the compiler and other necessary tools for building and running an application on a particular platform.

Version: Qt Creator allows you to have multiple versions of Qt installed on your development PC and use different versions to build your projects for different purposes. Qt Creator automatically detects the Qt versions that are registered by your system or by installers.

Debugger: The Qt Creator debugger plugin acts as an interface between the Qt Creator core and external native debuggers such as the GNU Symbolic Debugger (GDB), The debugger plugin automatically selects a suitable native debugger for each kit from the ones found on your system. You can also override this choice.

After these theories, let’s do it.

Create qt device

  • Bring up the options dialog using "Tools" -> "Options..."
  • Select the "Devices" page on the left, and click "Add..."
  • Select "Generic Linux Device" and click "Start Wizard".

Qt4.png

  • Specify proper settings and click "Next>"

Qt5.png

  • Click "Finish"
  • Device test finished successfully. Click "Close".

Qt6.png
If device test failed, please go back to specify proper settings.

  • Click "Apply".

Then, a device has been created succesfully.

Adding Compilers

  • Select the "Build & Run" page on the left, switch to "Compilers" tab, drop down "Add" menu and choose "GCC".

Qt7.png

  • Name the compiler as "TI-GCC"
  • Click "Browse..." to select "/usr/local/AM57xx/cross_compiler/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-g++"
  • Select ABI as “arm-linux-generic-elf-32bit”
  • Click "Apply”

Qt8.png

Adding Debuggers

  • Switch to the "Debuggers" tab
  • Click "Add"
  • Name the debugger as "ARM-GDB"
  • Click "Browse..." to select "/usr/local/AM57xx/cross_compiler/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gdb"
  • Click "Apply"

Qt9.png

Adding Qt Versions

  • Switch to the "Qt Versions" tab.
  • Check if the "Qt 5.5.0 (System)" is auto detected in "Manual" item ? If not, click "Add..." to choose the proper qmake.

Qt10.png

  • Click "Apply"

Adding Qt Kits

  • Switch to the "Kits" tab.
  • Click "Add"
  • Name the kit as "Emmabled Qt 5.5.0"
  • pecify the correct "Device Tpye", "Compiler", "Debugger" and "Qt version"(we have added).
  • Click "Browse..." to select "/usr/local/AM57xx/cross_compiler/linux-devkit/sysroots/" as sysroot.
  • Click Apply.

Qt11.png

  • Select “Emmabled Qt 5.5.0” and click “make default”.
  • Click OK to finalize the configuration.


Creating Qt Project

We have a demo to create a qt project as below:

  • Bring up "New" dailog using "File" -> "New File or Project..."
  • Select "Applications" -> 'Qt Widgets Application"
  • Click "Choose..."

Qt12.png

  • Use "hello_qt" as name
  • Create in "/home/adv/qt"
  • Click "Next"

Qt13.png

  • Uncheck "Desktop" and check "Emmabled Qt 5.5.0"
  • Click "Next"

Qt14.png

  • Use default settings for "Class Information"
  • Click "Next"
  • Use default settings for "Project Management"
  • Click "Finish"
  • Double click "hello_qt.pro" to switch to editor window
  • When you run the application, Qt Creator copies the necessary files to the device and starts the application on it. For example, adding
target.path = /root
INSTALLS += target

to the project .pro file will copy the binary of your project to /root on the remote device. Additional files can be deployed by adding them to further targets and adding those to INSTALLS as well.

Building Qt Project

  • Switch to "Projects" mode
  • Check if "build configuration" is set to "Debug".

Qt15.png

  • Select “Run”, and check if "Files to deploy" is correct

Qt16.png

  • Click “Add deploy steps”, select “Create tarball”.
  • Click “Add deploy steps”, select “Deploy tarball via SFTP upload”.

Qt17.png

  • Switch to "Edit" mode
  • Click "Build" to make qt project.


Deploying Qt Application

  • Right click your project and select the “Deploy” to upload the binary file to your target board. Note, Please ensure your target board connect to your host PC via LAN before all.

Qt18.png

  • You can also copy the binary file to your target board though U dsik directly.


Debugging Qt Application

  • Click debug icon to start debugging.

As we know, we have created the Qt device and we have added the gdb to kits. So, once the icon was kicked, the qtcreator will start the gdb server on your target board, and use the gdb client to connect the gdb server automatically.
Qt19.png
After this, a debug window will be popped as follow.
Qt20.png
Then, you can start to debug your qt code.


  • debug with anthor way Using GDB

When debugging on a target supported by GDB server, a local(host sides) GDB process talks to a GDB server running on the remote machine (target board)that controls the process to be debugged. The GDB server process is started on the remote machines by passing a port number and the executable:

gdbserver :1234 <executable>

It then typically responds:

Process bin/qtcreator created; pid = 5159
Listening on port 1234

On the local machine(host PC) that runs Qt Creator:

    • Select Debug > Start Debugging > Attach to Running Debug Server.
    • In the Host and port field, enter the name of the remote machine and the port number to use.
    • Select OK to start debugging.