QT on embedded Linux
QT is a very powerful and easy to use C++ library. Usually people think, that it is only good for cross-platform GUI development, but it has also a lot of features, that help in the development of measurement and control software on embedded Linux devices, that don't have any GUI.
See:
http://developer.qt.nokia.com/wiki/Support_for_Embedded_Linux
http://doc.qt.nokia.com/4.7/qt-embedded-install.html
We only want to use the following modules:
QtCore (2.7 MB)
QtNetwork (1.0 MB)
Why?
- fast, conveniant container classes, e.g. QList and QVector
- QCoreApplication implements a powerful event queue
- this event queue enables easy to use network support (UDP, TCP etc.)
- easy to use timers
- very convenient communication between classes, using slots and signals; also usable for inter-process communication
powerfull state machine framework, see: http://doc.qt.nokia.com/latest/statemachine-api.html
Installing QT for ARM
Download the QT sources:
cd ~ mkdir 00Software cd 00Software wget http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.4.tar.gz tar xzf qt-everywhere-opensource-src-4.7.4.tar.gz rm qt-everywhere-opensource-src-4.7.4.tar.gz cd qt-everywhere-opensource-src-4.7.4
Tell qmake to use the arm compiler.
Edit the file mkspecs/qws/linux-arm-g++/qmake.conf, so that it looks like this:
# Get the application to invoke the dynamic linker from the CodeSourcery sysrootl QMAKE_LFLAGS += -Wl,--dynamic-linker=/sysroot/lib/ld-linux.so.3 include(../../common/g++.conf) include(../../common/linux.conf) include(../../common/qws.conf) # modifications to g++.conf QMAKE_CC = arm-none-linux-gnueabi-gcc QMAKE_CXX = arm-none-linux-gnueabi-g++ QMAKE_LINK = arm-none-linux-gnueabi-g++ QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++ QMAKE_RPATHDIR = /sysroot/lib:/sysroot/usr/lib:/usr/local/Trolltech/QtEmbedded-4.7.4-arm/lib:/usr/local/Google/protobuf-2.4.1-arm/lib # modifications to linux.conf QMAKE_AR = arm-none-linux-gnueabi-ar cqs QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy QMAKE_STRIP = arm-none-linux-gnueabi-strip load(qt_config)
Run ./configure. To see the options, that are available, type:
cd ../../.. ./configure -embedded -help
Select the options, that you want, e.g.:
./configure -opensource -confirm-license -no-qt3support -release -nomake examples -nomake demos -no-multimedia -no-phonon -no-webkit -no-gui -no-cups -no-largefile -embedded arm -little-endian -xplatform qws/linux-arm-g++
Compile and install QT for ARM:
make -j2 sudo make install
For convenient cross-compiling from the command line, enter:
cd /usr/local/Trolltech/QtEmbedded-4.7.4-arm/bin sudo cp qmake qmake-arm cd ~ joe .bashrc Add the line: export PATH=$PATH:/usr/local/Trolltech/QtEmbedded-4.7.4-arm/bin close terminal restart terminal
You should now be able to compile QT console programs for ARM with the command sequence:
qmake-arm make
Simple console program (main.cpp):
#include <QtCore/QCoreApplication>
#include <QDebug>
#include <QTimer>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
qDebug() << "Hello World!";
QTimer::singleShot(50, &app, SLOT(quit())); //stop after 50 ms
return app.exec();
}To compile this, you need the follwoing project file (HelloWorld_QT.pro):
QT += core QT -= gui QT -= network TARGET = HelloWorld_QT CONFIG += console CONFIG -= app_bundle TEMPLATE = app SOURCES += main.cpp
Back to FrontPage