2011. 6. 27.

Android 용 Qt Framework compile 하는 방법

준비해야 하는 사항
  • 최신의 Official Android NDK를 다운로드 하고 설치한다.
  • 최신의 Official Android SDK를 다운로드 하고 설치한다.
--------------------------------------------------------------------------------
Android-lighthouse Repository를 Gitorious clone(gitorious에 대한 정보는 Googling해 보시길)

# git clone git://gitorious.org/~taipan/qt/android-lighthouse.git



Prepare & compile Qt

"Qt android-lighthouse" git clone시킨 폴더로 이동하여 "androidconfigbuild.sh"을 실행시킨다.
"androidconfigbuild.sh"을 기존의 qt configure와 동일한 역할을 하며, Qt를 처음 설치할때 한번만 실행시켜 주면 된다.

# cd /path/to/cloneOfandroid-lighthouse/,
# ./androidconfigbuild.sh -n "Android NDK를 설치한 폴더 절대경로" -q 1

만일 이미 설치 환경과 개발 framework가 구성되어 있는 상태에서 Qt만 컴파일 하기를 원한다면 아래와 같이 "-q 1" option을 제거하여 주면 된다.

# ./androidconfigbuild.sh -n "Android NDK를 설치한 폴더 절대 경로"

Android용 Qt-lighthouse 의 컴파일이 완료되면 컴파일된 Qt Library를 Android Device에 넣어 주어야 하는데 다음과 같은 방식으로 QtCreator를 이용하면 된다.
Target 에서 Testing 개발 중일 경우에는
 use device Qt library를 check해서 사용

Deploy를 원할 경우에는 Projects->Android (run tab)->Deploy configurations->Deploy local qt libs 옵션 사용



--------------------------------------------------------------------------------
androidconfigbuild.sh 은 아래와 같은 파라메터를 이용할 수 있다.
"androidconfigbuild.sh -p " 를 통하면 아래와 같은 help를 읽을 수 있다.


usage: ./androidconfigbuild.sh options



OPTIONS:

-p Shows this message

-c Clean qt

-q Qt build options

0 - don't configure qt (only compile) default

1 - configure qt and compile qt

-b Build qt

0 - don't build

1 - build

-s Install qt

0 - don't install

1 - install

-n NDK root. Default "/usr/local/android-ndk-r5b"

-o NDK host. Default "linux-x86"

-f NDK toolchain prefix. Default "arm-linux-androideabi"

-v NDK toolchain version. Default "4.4.3"

-a Target cpu architecture. Default "armeabi"

armeabi - tune for android arm v5

armeabi-v7a - tune for android arm v7

Optional name suffix: v5/v7

-h Shared

0 - Build static version of qt

1 - Build shared version of qt

-x Exceptions options

0 - don't use exceptions (you won't be able to build qtcreator with such a qt though)

1 - use exceptions

Optional name suffix: Xc/Nx

-d Build debug qt

Optional name suffix: D/R/DaR

-r Build release qt

Optional name suffix: R/D/DaR

-m Modify install path according to passed in options (name suffixes applied in above listed order).

-i Install path. Default "/home/your-name/path/to/android-lighthouse"

2011. 6. 15.

mips Target Board에서 Webkit을 올릴 때의 난감한 상황 undefined reference to `sinf'

mips 칩이 저렴해서 인지 settop box나 ipTV나 멀티미디어 플레이어에서 많이 사용된다.
하지만 최근 들어 피해 갈 수 없는 대세인 모듈이 있으니, 두둥 그것은 webkit
QtWebkit을 올리려면 rendering을 하는 측에서 (예를 들어 line이나 curve 등을 그릴때)
sine 이나 cosine 같은 삼각 함수를 쓰게 되는데
오래된 싸구려 mips 칩에서는 이를 지원하지 않는다..
uClibc 0.9.28 이상에서는 floating math 함수들을 지원한다.
uClibc 0.9.27 이하에서는 floating math 함수들을 지원하지 않는다.

문제점으로는 qline이나 curve 함수들이 컴파일 시 Link 되지 않는다.
undefined reference to `sinf'
undefined reference to `cosf'
undefined reference to `logf'

이를 해결 하기 위한 임시 대응책

$QTDIR/src/corelib/kernel/qmath.h
에다가

inline float sinf( float s)
{
   return (float)sin(s);
}


inline float cosf( float s)
{
   return (float)cos(s);
}

inline float logf( float s)
{
   return (float)log(s);
}

추가함

절대적으로 임시 방편이며, 속도가 많이 느려진다... 특히 Animation
그냥 uClibc 0.9.28 이상을 사용하시길....
양산 후 library 절대 올리기 싫어 하는 경우도 있긴 하지만... 이해는 어렵다...털썩...


2011. 6. 9.

Kbuntu 설치후 Qt 최신 설치할때 많이 요청 되어 지는 라이브러리

sudo apt-get install build-essential
처음에 개발자 도구 들이 설치 되지 않았을 때

sudo apt-get install libx11-dev
configure시 x11 관련 에러가 나왔을 때 : error: X11/Xlib.h: No such file or directory

sudo apt-get install libxext-dev
configure시 "cannot find -lXext" 와 같은 에러 메시지가 나왔을 때

sudo apt-get install libgstreamer0.10-dev
configure시 gstreamer가 설정되지 않을때

sudo apt-get install libxrender-dev
Webkit compile 시 "cannot find -lXrender"와 같은 에러 메시지가 나왔을 때



2011. 5. 31.

Official Qt Mobility 1.2.0 릴리스

Qt Mobility 플러그인 라이브러리가 2011년 5월 12일자로 1.2.0으로 Release 되었습니다.

Qt Mobility version 1.2.0 의 새로운 feature로 소개된 것들로는
- 기존 mobility module들의 개선 사항 추가
- Bluetooth device 와의 쉬운 integration 기능
- NFC ready device support
(Near Field Communication : 5m 이내 통신에 유용하며 RFID와 유사합니다)
- 그외 QtMessaging, QtServiceFramework, QtSensors 와 QML 지원 모듈들
http://doc.qt.nokia.com/qtmobility-1.2/index.html

다음에서 다운 로드 받아 사용하실 수 있습니다.
http://get.qt.nokia.com/qt/add-ons/qt-mobility-opensource-src-1.2.0.zip
http://get.qt.nokia.com/qt/add-ons/qt-mobility-opensource-src-1.2.0.tar.gz

Meego 사용자의 경우 : http://download.meego.com/live/devel:/qt-mtf/Trunk/
sudo zypper addrepo http://download.meego.com/live/devel:/qt-mtf/Trunk/ devel-qt-mtf
sudo zypper refresh
sudo zypper install qt-mobility
sudo zypper install qt-mobility-example

Gitorious (깃토리오스) 사용자의 경우
http://qt.gitorious.org/ 에서 Qt-mobility의 'v1.2.0' Tag를 사용하실 수 있습니다.

2011. 5. 30.

Qt Signal 과 QML function 을 연결하기

QML은 UI를 구성하는 데 편의성을 제공하기는 하지만
Native code처럼 정밀한 작업을 하거나 세밀한 조작을 할때는 답답한 부분이 상당히 있다.

그래서 UI 는 QML로 구성하고, 세밀하고 빠른 속도를 요구되어지는 부분은
Qt로 구성하는 경우가 많은데, 이때 주의해야 할 부분이 QML과 Signal/Slot을 Communicate할 수 있느냐이다.

결론부터 말하자면
rootObject() 와 QVariant를 사용해서 Signal/Slot을 QML에서도 사용할 수 있다.

조금 더 상세히 말하자면 QML 파일은 결국 QDeclarativeView를 사용하여 동작이 이루어지게 되는데, 이 QDeclarativeView를 통하여 QML Controller의 pointer를 가져 올 수 있다.

QDeclarativeView view;
view.setSource( QUrl("QML파일.qml"));

QObject *rootObject = dynamic_cast(view.rootObject());

object의 포인터를 가져 오게 되면 그 다음은 일반 Qt 프로그램과 동일 해 진다.
QObject::connect(rootObject, SIGNAL(.....), &QtClass pointer, SLOT(....));
QObject::connect(&QtClass pointer, SIGNAL(...), rootObject, SLOT(...));

그리고 QML 파일과 Qt Native 사이의 parameter는 QVariant를 통하여 전달 시키면 된다.
NativeFunction( QVariant text ); // Qt
function QMLFunction( text ) // QML

다음의 forum nokia 예제를 참조한다.
<참조>
http://wiki.forum.nokia.com/index.php/CS001625_-_Connecting_Qt_signal_to_QML_function

myclass.h

#ifndef __MYCLASS_H__
#define __MYCLASS_H__

#include <qobject>
#include <qvariant>

class MyClass : public QObject
{
Q_OBJECT

public:
MyClass() {}

public slots:
void getData() {
QString text("New data");
emit data(QVariant(text));
}

signals:
void data(QVariant data);
};

#endif

main.cpp


#include <qapplication>
#include <qgraphicsobject>
#include <qdeclarativeview>
#include "myclass.h"


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MyClass myClass;

QDeclarativeView view;
view.setSource(QUrl("./ui.qml"));
view.setResizeMode(QDeclarativeView::SizeRootObjectToView);

QObject *rootObject = dynamic_cast(view.rootObject());

QObject::connect(rootObject, SIGNAL(dataRequired()), &myClass, SLOT(getData()));
QObject::connect(&myClass, SIGNAL(data(QVariant)), rootObject, SLOT(updateData(QVariant)));

view.setGeometry(QRect(100,100,800, 480));
view.show();

return app.exec();
}


ui.qml

import Qt 4.7

Rectangle {
signal dataRequired;

function updateData(text) { dataText.text = text } // slot

anchors.fill: parent; color: "black"

Text {
id: dataText
anchors.centerIn: parent; color: "white"
}

MouseArea {
anchors.fill: parent
onClicked: dataRequired()
}
}

Qt Cross-compiling with Scratchbox2

Embedded 환경 구축을 위한 Cross-compiling은 누가 뭐래도 지루하고 따분한 일에는 틀림 없다.

특히 Qt와 같이 다양한 기능을 제공하는 Platform Cross-compile에는 더 많은 정성과 신경이 쓰인다.
게다가 Hardware 가속기능이나 멀티미디어 라이브러리를(DirectFB, D-Bus, GStreamer, OpenGL ES)
지원하기 위해서는 Optimization도 많고, Testing까지 생각한다면 Cross-compiling Tool의 사용은
선택이 아니라 필수의 항목일 수 있다.
( 하드웨어 가속기나 멀티미디어 항목은 귀찮치만 신경을 쓰면 쓸수록 Application의 성능과 연관성도 높다)

따라서 Scratchbox2를 반복적으로 쓰면서 나름 편리하다고 느껴진 방법을 정리해 보았다.

1) Scratchbox2를 Host 에 설치한다.

2) 제공된 Board SDK 를 이용하여 root image를 만든다.

3) Target rootfs 루트폴더로 이동한다.
Scratchbox2 의 sb2-init 은 반드시 targetfs 의 root에서 실행 시켜줄 것을 권장한다.
예) cd ~/Tegra2Arm/vibrante-devlite-p1138/targetfs

4) scratchbox 2 env 를 만들어 준다.
예 ) sb2-init Tegra2Qt ~/toolchains/tegra2-x.x.x/bin/arm-none-linux-gnueabi-gcc
sb2-init -c qemu-arm Tegra2QPA ~/toolchains/tegra2-x.x.x/bin/arm-none-linux-gnueabi-gcc
sb2-init [option].... [Target Name] [Compiler:specs] [secondary_compiler]

5) Scratchbox2 가상환경으로 들어 간다.
예) sb2 -t Tegra2QPA
sb2 -t [Target Name]

6) Qt Configuration

- makespec set to use host-g++ and friends (builds tools for host)
- xmakespec set to linux-g++
예) configure -platform linux-tegra2-g++ -arch arm -xplatform linux-g++ -no-neon -graphicssystem raster -opengl es2 -confirm-license -force-pkg-config
여기서 가장 중요한 요소는 -force-pkg-config 인데, opengl es2나 dbus driver들이 제대로 맞물릴 수 있도록
해당 Target pkgconfig 위치가 $PKG_CONFIG_PATH를 정확히 지정 할 수 있도록 한다.


# # qmake configuration for linux-g++ #

MAKEFILE_GENERATOR = UNIX

TEMPLATE = app

CONFIG += qt warn_on release incremental link_prl

QT += core gui

QMAKE_INCREMENTAL_STYLE = sublib

include(../../common/g++.conf)

include(../../common/linux.conf)

# modifications to g++.conf

QMAKE_CC = sb2 gcc

QMAKE_CXX = sb2 g++

QMAKE_LINK = sb2 g++

QMAKE_LINK_SHLIB = sb2 g++

# modifications to linux.conf

QMAKE_AR = sb2 ar cqs

QMAKE_OBJCOPY = sb2 objcopy

QMAKE_STRIP = sb2 strip

load(qt_config)



- force-pkg-config (we are still cross compiling and hence have to explicitly enable pkg-config use )
export PKG_CONFIG_PATH=$TARGET_DIR/usr/lib:$TARGET_DIR/usr/local/lib



2011. 5. 27.

QML 에서 mp3 file playback



QML은 Qt 용 Application 개발시 UI의 요소를 빨리 개발하기 위한 Markup 언어로,
iPhone이나 Cocoa 개발시 사용되는 xib 파일과 비슷한 개념이라고 생각할 수 있다.

QML에서 mp3 file playback은 다음과 같이 간단히 만들수 있는데

예제는 QDeclarativeView를 이용해서 Binary 실행 파일의 일부로 만들어 주거나
# qmlviewer main.qml
과 같이 실행 시켜 주면 된다.

19줄로 만드는 mp3 player 는 backend가 필요한데
backend는 Qt-mobility 와 OS 별 multimedia backend가 필요하다

OS 별 multimedia backend
예) GStreamer , DirectShow, QuickTime 등