UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

AR# 59172

PetaLinux - Building and Deploying Applications With Qt 4.8.5, QWT 6.1.0, Qt Creator 3.0

Description

Qt is an applications framework well-suited for embedded systems development. In addition to providing a framework for GUIs and embedded graphics via direct access to the frame buffer under Linux, it provides a rich suite of framework such as multi-threading, networking, database interaction, and more. Xilinx Targeted Reference Designs (TRDs) for Zynq are built on the Qt framework plus QWT, the Qt Widgets for Technical Applications plugin. This document describes how to build the libraries, integrate them into PetaLinux, and develop software on the Qt platform for Zynq under PetaLinux 2013.10.

Solution

While the TRDs make extensive use of the Qt framework, Qt is not a standard part of the PetaLinux installation. It must be downloaded and built separately. Then the Qt framework must be included into a PetaLinux root file system before it can be used. As of this writing, the current versions of Qt, QWT, Qt Creator, and PetaLinux are:

Application / Library Version Download Website
Qt 4.8.5 http://www.qt-project.org
Qt Widgets for Technical Applications 6.1.0 http://qwt.sourceforge.net
Qt Creator 3.0.0 http://www.qt-project.org
PetaLinux 2013.10

http://www.xilinx.com

In order to integrate Qt into a PetaLinux system successfully PetaLinux must be configured with a display controller that provides a frame buffer interface such as the Xylon LogiCVC-ML video display controller. Building the display controller IP and configuring the kernel to use it are outside the scope of this tutorial. If you wish to skip the compilation step, please download the PetaLinux Qt 4.8.5 plugin at the end of this article and skip to the "Integrating with PetaLinux" section. Also, this Answer Record assumes that the PetaLinux build system uses TCSH and BASH on the PetaLinux target. If not, please make the appropriate corrections to the command examples/samples throughout the tutorial (note that these are the defaults, so most users will not need to do this).

Preparing to Build

In order to cross compile the libraries a cross-compiler must be available in the command path (eg, $PATH). Typically this will be the CodeSourcery toolchain shipped with the Xilinx SDK, and therefore that's the compiler used throughout this tutorial. If you wish to use another compiler, you will need to make the appropriate syntax corrections to the examples provided. To set up the compiler, ensure that the arm-xilinx-linux-gnueabi-* tools are in the command path and that the $CROSS_COMPILE environment variable is defined appropriately.

build> setenv PATH $XILINX_SDK/gnu/arm/lin/bin:${PATH}

You will also need to create a directory structure for cross-compiling the libraries and moving them to a staging area before an install. Create directories that look like this:

$WORK_DIR/
+-> Qt/
+-> build/
+-> install/

Download the Qt and QWT install files to the Qt/build directory. When downloading Qt, ensure that you select the Qt for Embedded Linux distribution as it includes additional files necessary to interact directly with the kernel frame buffer on embedded devices. Also, do not download Qt5 at this time. Qt5 requires OpenGL graphics processing which is not available on Zynq without additional IP. After the download, you should have two files:

qt-everywhere-opensource-src-4.8.5.tar.gz
qwt-6.1.0.tar.bz2

Building Qt

Building the main Qt library is fairly straightforward as the library itself includes mkspecs (build specifications) for different cross compilation environments including embedded ARM. However, we need to make a small modification to the build scripts as our compiler is named slightly differently than the example.

First, extract the archive:

build> cd $WORK_DIR/Qt/build
build> tar -zxvf qt-everywhere-opensource-src-4.8.5.tar.gz
build> cd qt-everywhere-opensource-src-4.8.5

We will also define a helper environment variable to contain the install path for Qt.

build> setenv ZYNQ_QT_INSTALL ${WORK_DIR}/Qt/install

At this point, you will need to edit the Qt configuration file for the qws/linux-arm-gnueabi-g++ build target. Open this file in a text editor and note that the referenced compiler is called arm-none-linux-gnueabi-*. Find and replace each instance of that compiler name with arm-xilinx-linux-gnueabi-*.

mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf

Also, to ensure that follow-on qmake projects are built correctly we need to add instructions for the qmake utility down the line. Your completed file will look like this (note that if you do not intend to set the $ZYNQ_QT_INSTALL variable permanently, you will likely want to replace it with the actual hard-coded path). Changes and additions are highlighted in red.

#
# qmake configuration for building with arm-xilinx-linux-gnueabi-g++
#
include(../../common/gcc-base-unix.conf) include(../../common/g++-unix.conf) include(../../common/linux.conf) include(../../common/qws.conf)
# modifications to g++.conf QMAKE_CC = arm-xilinx-linux-gnueabi-gcc QMAKE_CXX = arm-xilinx-linux-gnueabi-g++ QMAKE_LINK = arm-xilinx-linux-gnueabi-g++ QMAKE_LINK_SHLIB = arm-xilinx-linux-gnueabi-g++
# modifications to linux.conf QMAKE_AR = arm-xilinx-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-xilinx-linux-gnueabi-objcopy
QMAKE_STRIP = arm-xilinx-linux-gnueabi-strip
QMAKE_CFLAGS="-I$(ZYNQ_QT_INSTALL)/include -DZYNQ"
QMAKE_CXXFLAGS="-Wno-psabi -I$(ZYNQ_QT_INSTALL)/include -DZYNQ"
QMAKE_LFLAGS="-L$(ZYNQ_QT_INSTALL)/lib"

load(qt_config)

Once you have made these changes, run the configuration utility for Qt. The pre-build library included in this document was built with these settings, but there are many more. A complete list of available switches can be found on the Qt Project website and in the Qt documentation.

build> ./configure -embedded arm \
-xplatform qws/linux-arm-gnueabi-g++ \ -little-endian \ -opensource \
-host-little-endian \
-confirm-license \ -nomake demos \ -nomake examples \ -prefix $ZYNQ_QT_INSTALL

Once configuration is complete, we can build and install the library:

build> make
build> make install

At this point, the Qt build is complete and copied to the staging area.

Note: Qt for embedded systems handles fonts in a non-standard manner. A standard set of fonts will be installed to $ZYNQ_QT_INSTALL/lib/fonts. Additionally, a path to this location will be HARD CODED into the library itself. When installed on the target embedded system, Qt applications will look in $WORK_DIR/Qt/install/lib/fonts and will fail if that directory is not found, as it likely won't be. You can fix this by setting the $QT_QWS_FONTDIR environment variable on the target architecture, which we will do in the section titled "Integrating with PetaLinux".

Building Qt Widgets for Technical Applications

QWT is a smaller library than Qt so it is faster to build and install. Also, it leverages the Qt build mechanism which makes it very straightforward to configure and deploy. We no longer need to edit compiler settings as we can re-use our settings from the Qt build. We do, however, need to ensure that the Qt build tools are on the path:

build> setenv PATH ${ZYNQ_QT_INSTALL}/bin:$PATH

The next step is to change to the build directory and extract the QWT source:

build> cd $WORK_DIR/Qt/build
build> tar -jxvf qwt-6.1.0.tar.bz2
build> cd qwt-6.1.0

QWT contains some additional libraries, plugins, etc. that will not compile correctly for an embedded system, so we need to edit the qwtconfig.pri file in the QWT root directory. Do so, and ensure that it looks like this (as above, changes from the default are highlighted in red):

################################################################
# Qwt Widget Library
# Copyright (C) 1997   Josef Wilgen
# Copyright (C) 2002   Uwe Rathmann
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the Qwt License, Version 1.0
################################################################
QWT_VER_MAJ = 6 QWT_VER_MIN = 1 QWT_VER_PAT = 0 QWT_VERSION = $${QWT_VER_MAJ}.$${QWT_VER_MIN}.$${QWT_VER_PAT}
###################################################################### # Install paths ######################################################################
QWT_INSTALL_PREFIX = $$[QT_INSTALL_PREFIX]
unix { QWT_INSTALL_PREFIX = /usr/local/qwt-$$QWT_VERSION }
win32 { QWT_INSTALL_PREFIX = C:/Qwt-$$QWT_VERSION }
QWT_INSTALL_DOCS = $${QWT_INSTALL_PREFIX}/doc QWT_INSTALL_HEADERS = $${QWT_INSTALL_PREFIX}/include QWT_INSTALL_LIBS = $${QWT_INSTALL_PREFIX}/lib
###################################################################### # Designer plugin # creator/designer load designer plugins from certain default # directories ( f.e the path below QT_INSTALL_PREFIX ) and the # directories listed in the QT_PLUGIN_PATH environment variable. # When using the path below QWT_INSTALL_PREFIX you need to # add $${QWT_INSTALL_PREFIX}/plugins to QT_PLUGIN_PATH in the # runtime environment of designer/creator. ######################################################################
QWT_INSTALL_PLUGINS = $${QWT_INSTALL_PREFIX}/plugins/designer # linux distributors often organize the Qt installation # their way and QT_INSTALL_PREFIX doesn't offer a good # path. Also QT_INSTALL_PREFIX is only one of the default # search paths of the designer - not the Qt creator
#QWT_INSTALL_PLUGINS = $$[QT_INSTALL_PREFIX]/plugins/designer
###################################################################### # Features # When building a Qwt application with qmake you might want to load # the compiler/linker flags, that are required to build a Qwt application # from qwt.prf. Therefore all you need to do is to add "CONFIG += qwt" # to your project file and take care, that qwt.prf can be found by qmake. # ( see http://doc.trolltech.com/4.7/qmake-advanced-usage.html#adding-new-configuration-features ) # I recommend not to install the Qwt features together with the # Qt features, because you will have to reinstall the Qwt features, # with every Qt upgrade. ######################################################################
QWT_INSTALL_FEATURES = $${QWT_INSTALL_PREFIX}/features # QWT_INSTALL_FEATURES = $$[QT_INSTALL_PREFIX]/features
###################################################################### # Build the static/shared libraries. # If QwtDll is enabled, a shared library is built, otherwise # it will be a static library. ######################################################################
QWT_CONFIG += QwtDll
###################################################################### # QwtPlot enables all classes, that are needed to use the QwtPlot # widget. ######################################################################
QWT_CONFIG += QwtPlot
###################################################################### # QwtWidgets enables all classes, that are needed to use the all other # widgets (sliders, dials, ...), beside QwtPlot. ######################################################################
QWT_CONFIG += QwtWidgets
###################################################################### # If you want to display svg images on the plot canvas, or # export a plot to a SVG document ######################################################################
QWT_CONFIG += QwtSvg
###################################################################### # If you want to use a OpenGL plot canvas ######################################################################
#QWT_CONFIG += QwtOpenGL
###################################################################### # You can use the MathML renderer of the Qt solutions package to # enable MathML support in Qwt. Because of license implications # the ( modified ) code of the MML Widget solution is included and # linked together with the QwtMathMLTextEngine into an own library. # To use it you will have to add "CONFIG += qwtmathml" # to your qmake project file. ######################################################################
#QWT_CONFIG += QwtMathML
###################################################################### # If you want to build the Qwt designer plugin, # enable the line below. # Otherwise you have to build it from the designer directory. ######################################################################
#QWT_CONFIG += QwtDesigner
###################################################################### # Compile all Qwt classes into the designer plugin instead # of linking it against the shared Qwt library. Has no effect # when QwtDesigner or QwtDll are not both enabled. # # On systems where rpath is supported ( all Unixoids ) the # location of the installed Qwt library is compiled into the plugin, # but on Windows it might be easier to have a self contained # plugin to avoid any hassle with configuring the runtime # environment of the designer/creator.
######################################################################
win32 { QWT_CONFIG += QwtDesignerSelfContained }
###################################################################### # If you want to auto build the examples, enable the line below # Otherwise you have to build them from the examples directory. ######################################################################
#QWT_CONFIG += QwtExamples
###################################################################### # The playground is primarily intended for the Qwt development # to explore and test new features. Nevertheless you might find # ideas or code snippets that help for application development # If you want to auto build the applications in playground, enable # the line below. # Otherwise you have to build them from the playground directory. ###################################################################### #QWT_CONFIG += QwtPlayground ###################################################################### # When Qt has been built as framework qmake wants # to link frameworks instead of regular libs ######################################################################
macx:!static:CONFIG(qt_framework, qt_framework|qt_no_framework) {
QWT_CONFIG += QwtFramework }

From the default configuration, we are configuring the QWT project to not build the designer plugin, not to build using OpenGL acceleration, not build the examples, and install to the Qt install area.

From this point forward, the build process is the same as any Qt application: run the qmake utility to generate Qt-specific makefiles, run make, and then run make install.

build> qmake qwt.pro
build> make
build> make install

With both Qt and QWT built, we can integrate them into PetaLinux as a precompiled library.

Integrating with PetaLinux

Now that both Qt and QWT are installed, we need to integrate them with the PetaLinux project so that the libraries will be included in the PetaLinux root file system. If the target system is not using initramfs, these instructions will not apply and you will need to take the necessary steps to integrate the libraries into your root file system (if you are not using the PetaLinux initramfs it is assumed that you already know how to do this; instructions for doing so are outside the scope of this tutorial).

It is also assumed that you already have a PetaLinux project created and configured. Building a PetaLinux project is outside the scope of this tutorial. A pre-built library is available as a link at the bottom of this document. If you wish to skip the rest of this section, download qt-4.8.5.tar.gz, extract it to the /components/libs directory of your PetaLinux project (creating the path if it doesnt exist), enable it, build the project, and skip to the Designing with Qt Creator section.

If you want to go through the process of creating the library under PetaLinux, the first step is to create a PetaLinux library template:

build> cd $PETALINUX_PROJECT_DIR
build> petalinux-create -t libs -n qt-4.8.5 --enable

This will create the directory structure components/libs/qt-4.8.5 under your project. This will also create an example library template, which we will not use and need to delete.

build> cd components/libs/qt-4.8.5
build> rm libqt*

We will first copy the contents of the Qt library lib directory as a subdirectory of our component:

build> cp -Pr $ZYNQ_QT_INSTALL/lib .

This copies the object files any symbolic links necessary for Qt and QWT, but we need to handle the fonts. As mentioned in the Building Qt section, we need to ensure that the $QT_QWS_FONTDIR environment variable is set correctly on the PetaLinux target. Fortunately, PetaLinux provides a mechanism to accomplish this: we can create a small initialization script and place it into /etc/profile.d/ on the initramfs. It will then be called as a part of the standard /etc/profile and apply to any login shell on the system.

Create a file called profile.qt-4.8.5 and add these lines to it:

QT_QWS_FONTDIR=/usr/lib/fonts
export QT_QWS_FONTDIR

Now we need to edit the project's Makefile to copy the libraries and this new profile extension to their proper directories in the target file system. Note that because we have already built the library, the build and clean targets are empty. Edit the Makefile to look like this (noting that you must use tabs and not spaces for the indents):

ifndef PETALINUX
$(error "Error: PETALINUX environment variable not set.  Change to the root of your PetaLinux install, and source the settings.sh file")
endif
include libs.common.mk
all: build install
.PHONY: build build:
install: # Install libraries and fonts to the rootfs
mkdir -p $(TARGETDIR)/usr/lib rsync -ar ./lib/* $(TARGETDIR)/usr/lib/
# Install the script to ensure the font directory is properly specified mkdir -p $(TARGETDIR)/etc/profile.d cp profile.qt-4.8.5 $(TARGETDIR)/etc/profile.d/profile.qt-4.8.5
clean:

At this point, the library is fully installed into the PetaLinux project. Enable the library and build PetaLinux before proceeding to the next step.

build> petalinux-config -c rootfs

build> petalinux-build

NOTE: Qt is a C++ framework and thus requires that the C++ libraries are installed on your PetaLinux root file system. This can be done by enabling the libstdc++6 library via petalinux-config -c rootfs in your PetaLinux project.

Designing with Qt Creator

Designing GUI applications by hand can be tedious, and Qt is no exception. To alleviate this, the Qt Project provides a development GUI called Qt Creator that combines a full C++ IDE, GUI editing, source control, and debugging. The IDE is designed in a way that will easily allow for cross compiling, building, and deploying Zynq Linux applications (whether using the Qt framework or not). The final section of this document describes how to configure the IDE for use with a Qt project targeting Zynq.

First, you need to download and install the Qt Creator tool. This is as simple as extracting the archive and running the tool from the /bin directory, so this tutorial wont show those steps.

Once the IDE is launched, Go to the Tools -> Options menu and select the Build & Run tab from the items on the left-hand side. With the Kits tab selected, press Add. Create a new target called "PetaLinux" and configure it as shown in the picture below:


Many of the tabs will not have defined default values. On Device, press the Manage button to configure the Zynq board. Fill in the settings on this tab for your Zynq device. If you are unable to connect via SSH, ensure that dropbear is installed in your PetaLinux application and that you have a valid IP address on your Zynq board. Use gdbserver as the GDB server executable.


For the compiler, again click Manage to configure the Xilinx Zynq cross compiler. Click the Add button to add the new toolchain and point to the gcc executable.


S

imilarly, for the Qt version point to the qmake executable under your Qt install directory ($WORK_DIR/Qt/install/bin).

You will now be able to create a new project for the Zynq kit that you've created. One step remains: we need to configure the project for use with the Zynq target. This requires two steps. The first is to configure the qmake.pro file for the project to include information about the download directory for the embedded Linux target. Edit the qmake.pro file to add these lines:

linux-* {
        target.path = /home/root
                INSTALLS += target
}

Finally, configure the Project -> Run options in Qt Creator as follows. Remove the free disk space check and ensure that the -qws line is appended as a command line argument to the file. Congratulations! You can now build and debug Qt applications for PetaLinux from your Linux desktop with Qt creator.


Attachments

Associated Attachments

Name File Size File Type
qt-4.8.5.tar.gz 14 MB GZ
AR# 59172
Date Created 01/20/2014
Last Updated 07/07/2014
Status Active
Type General Article
Devices
  • Zynq-7000Q
  • Zynq-7000
  • XA Zynq-7000
  • SoC
Tools
  • PetaLinux
  • PetaLinux - 2013.10