Qt

How to get RSS flux in QML

For this example, i using the QtQuick 1.1, but normally, you shouldn’t have problem if you use the newer version of QtQuick.

For this example, i getting the RSS from http://vianavigo.com/fr/actualites-trafic/rss-vianavigo-vos-transports-en-commun-en-ile-de-france-optile-ratp-sncf/?type=102

XmlListModel{
id: xmlModel
source: "http://vianavigo.com/fr/actualites-trafic/rss-vianavigo-vos-transports-en-commun-en-ile-de-france-optile-ratp-sncf/?type=102"
query: "/rss/channel/item
namespaceDeclarations: "declare namespace content=\"http://purl.org/rss/1.0/modules/content/\";"   //For getting content:encoded !!
XmlRole { name: "pubDate"; query: "pubDate/string()" }
XmlRole { name: "titre"; query: "title/string()" }
XmlRole { name: "description"; query: "description/string()" }
XmlRole { name: "detail"; query: "content:encoded/string()" }            //You should declare the namespace for getting this parameters
}

And now your xmlModel is ready you can use

ListView{
id: listView
model: xmlModel
}

For getting this example :

media:thumbnail url="<a href="http://farm5.static.flickr.com/4048/4362801851_b80289ca0e_s.jpg">http://farm5.static.flickr.com/4048/4362801851_b80289ca0e_s.jpg</a>"height="75" width="75"

 

XmlRole { name: "thumbnail"; query: 'media:thumbnail/@url/string()' }

How to get appVersion with Qt and QML

You want get the app version from your .pro file. Is very simple !

In your .pro write this :

VERSION += 0.3.0
DEFINES += APPLICATION_VERSION=\"\\\"$$VERSION\\\"\"

Save it: CTRL+S

Now when your write APPLICATION_VERSION in your application, you can get when version here 0.3.0.

For using it in your QML, write in your main.cpp

viewer.rootContext()->setContextProperty("appVersion", APPLICATION_VERSION);

In your QML:

Rectangle{
     Text{
          id: myText
          text: appVersion
     }
}

How to compile Qt lib with crosstool-ng for Raspberry

If you haven’t install crosstool-ng you can read this tuto :

https://beter93.wordpress.com/2013/03/20/cross-compilation-with-crosstools-ng-for-raspberry/

Download your Qt lib for linux :

All (old) version available here : ftp://ftp.qt-project.org/qt/source/

Extract it :

tar xvf qt-everywhere-opensource-src-4.6.2.tar.gz
cd qt-everywhere-opensource-src-4.6.2

Now go to :

cd mkspecs/qws
mkdir rasp-g++
cp linux-arm-g++/* rasp-g++
cd rasp-g++

Here, qmake.conf is very important file. On this conf file, you should write the path of your arm g++/gcc compiler.

My qmake.conf file :

 #
 # qmake configuration for building with arm-linux-gnueabi-g++
 #
 include(../../common/linux.conf)
 include(../../common/gcc-base-unix.conf)
 include(../../common/g++-unix.conf)
 include(../../common/qws.conf)
MAKEFILE_GENERATOR      = UNIX
 TARGET_PLATFORM         = unix
 TEMPLATE                = app
 CONFIG                  += qt warn_on release incremental link_prl gdb_dwarf_index
 QT                      += core gui
 QMAKE_INCREMENTAL_STYLE = sublib
 PATH_ARM        = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin
#QMAKE_CFLAGS_RELEASE = -O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
 #QMAKE_CXXFLAGS_RELEASE = -O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=softfp
# modifications to g++.conf
 QMAKE_CC                = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-gcc
 QMAKE_CXX               = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++
 QMAKE_LINK              = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++
 QMAKE_LINK_SHLIB        = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-g++
# modifications to linux.conf
 QMAKE_AR                = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-ar cqs
 QMAKE_OBJCOPY           = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-objcopy
 QMAKE_STRIP             = /home/yekmen/x-tools/arm-unknown-linux-gnueabi/bin/arm-unknown-linux-gnueabi-strip
load(qt_config)

Configure your installation for our lovely Raspberry ❤ :

./configure -lrt -opensource -confirm-license -prefix /opt/qt-arm -no-qt3support -embedded arm -little-endian -xplatform qws/rasp-g++ -fast -no-xinput -no-xrandr -no-openvg -no-opengl -no-gtkstyle -no-nis -no-cups -xmlpatterns -exceptions -no-stl -no-accessibility -no-audio-backend -no-multimedia -no-xfixes -no-mitshm

When your configuration was finished launch make:

make -j4

After 1 or 2 hours … your lib is ready for USE !! If you use make install your lib is here : /opt/qt-arm also, into the lib folder of your qt-evrywhereXXXXX.

Also … you can download my version : (Download Qt for Raspberry )

https://mega.co.nz/#!hhNQ3BZZ!T5KBa3WchTuJ6dOxLHMPp188h4ZcJGDW–tE3ipW634

Enjoy 😉

 

FAQ:

error1:

libQtCore.so: undefined reference to `QInotifyFileSystemWatcherEngine::create()’

Resolution:

edit ./src/corelib/io/io.pri

find linux-*:

append your cross-toolchain’s prefix after it

Example :

my toolchains’s prefix is arm-unknown-linux-gnueabi-XXX

– 77         linux-*|:!symbian {

+ 77         linux-*| arm-unknown-linux-gnueabi-*:!symbian {

78             SOURCES += \

79                     io/qfilesystemwatcher_inotify.cpp \

80                     io/qfilesystemwatcher_dnotify.cpp

81

82             HEADERS += \

83                     io/qfilesystemwatcher_inotify_p.h \

84                     io/qfilesystemwatcher_dnotify_p.h

85         }

86

87         freebsd-*|macx-*|darwin-*|openbsd-*:{

88             SOURCES += io/qfilesystemwatcher_kqueue.cpp

89             HEADERS += io/qfilesystemwatcher_kqueue_p.h

90         }

error2:

libQtCore.so: undefined reference to `clock_gettime’

Resolution:

./configure -lrt

error3:

libQtGui not found :

vim projects.pro

comments : and re lauch ./configure … and make

for(PROJECT, $$list($$lower($$unique(QT_BUILD_PARTS)))) {
isEqual(PROJECT, tools) {
SUBDIRS += tools
} else:isEqual(PROJECT, examples) {
#      SUBDIRS += examples
} else:isEqual(PROJECT, demos) {
#       SUBDIRS += demos

How to compile GCC and use a cross compilation with Qt Creator

In this post, we see how to compile and use a cross compilation with Qt Creator.

Install this :

sudo apt-get install gcc-multilib

Install the build dependencies:

sudo apt-get build-dep gcc-4.5

Add this at end of your ~/.bashrc

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch)
export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)

Firstly, download your version of GCC. For this example, i useGCC 4.3.2:

( All version of gcc : ftp://ftp.uvsq.fr/pub/gcc/releases/ )

wget ftp://ftp.uvsq.fr/pub/gcc/releases/gcc-4.3.2/gcc-4.3.2.tar.gz

Extracting it :

tar xvf gcc-4.3.2.tar.gz

Going in this folder:

cd gcc-4.3.2

Now you can seeing if your system can compile gcc :

./configure –prefix=/usr/local/gcc/your_GCC_Version -with-gmp-include=/usr/lib/gmp.h –disable-multilib –enable-language=c,c++

In language parameters, if you use gcc for Java, ada or other you can add it. for example :

–enable-language=c,c++,java,ada …

If you have no error with configure, now you can launch make:

make -j2

If you have 4 core or higher you can use make -jNb_of_core, now … you must waiting hmmm … between 30min at 1hours.

When is finished, you can open QtCreator: Tools -> Compiler->ToolChain add a new configuration, path of gcc is /usr/local/gcc/your_gcc_version/g++

For know if your application used your new version of gcc :

strings -a yourApp | grep GCC

FAQ :

At configure GMP or MPFR missing:

Download GMP

wget ftp://ftp.gmplib.org/pub/gmp-5.1.1/gmp-5.1.1.tar.lz

tar xvf gmp-5.1.1.tar.lz

cd gmp-5.1.1

./configure

make -j2 && sudo make install

Problem gnu/stubs-32.h missing,

use –disable-multilib when doing  ./configure.

or

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch)
export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)

Add this at end of your ~/.bashrc

export LIBRARY_PATH=/usr/lib/$(gcc -print-multiarch)
export C_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)
export CPLUS_INCLUDE_PATH=/usr/include/$(gcc -print-multiarch)