在QT SDK下構建MeeGo Touch開發環境
在陸續推出MeeGo移動終端設備開發UI設計基礎等教程之后,我們將為大家介紹一些MeeGo開發環境的教程。也許有不少朋友會問到,網上有不少構建MeeGo Touch環境的文章了,你又何必多此一舉呢?細心的朋友可能會發現,我這里不用編譯QT4.7 而是用QT4.7的SDK來搭建環境的。編譯QT4.7一般都需要大概一下午的時間,而是用SDK則最多不超過20分鐘就搞定了。這也是希望能有更快的方法讓大家來玩MeeGo。
QT-sdk-linux-x86-opensource-2010.05-rc1.bin下載
1.安裝 QT-sdk-linux-x86-opensource-2010.05-rc1.bin命令:
- chmod 777 QT-sdk-linux-x86-opensource-2010.05-rc1.bin
- ./QT-sdk-linux-x86-opensource-2010.05-rc1.bin
2.下載編譯好的dbus庫文件(附件里),放到QT 2010.05的庫里。
安裝g++
- sudo apt-get install g++
3.安裝依賴庫文件:
(1) 安裝依賴庫
- sudo apt-get install libfontconfig1-dev libfreetype6-dev libx11-dev libxcursor-dev libxext-dev libxfixes-dev libxft-dev libxi-dev libxrandr-dev libxrender-dev
(2) 安裝dbus庫
- sudo apt-get install libgconf2-dev libdbus-QT-1-dev
(3)修改libmeegotouch/configure,將HAVE_DBUS=no改為yes
4.安裝meegotouch-theme(這個主要是一些主題css文件等)
(1) 下載meegotouch-theme 代碼
- git clone git://gitorious.org/meegotouch/meegotouch-theme.git
然后執行 chmod 777 -R libmeegotouch, 給下載下來的源碼全部加上最高權限
(2) 進入目錄meegotouch-theme。
- cd meegotouch-theme/
(3) 執行qmake 生成makefile :
- qmake
(4) 安裝
- sudo make install
說明:
在使用make的時候可能會說make的版本不是4.7。出現qmake與qt4的連接問題
可以敲下面命令測試
- $qmake -v
出現下面情況:
- $Qmake version: 1.07a (QT 3.3.8b)
- $Qmake is free software from Trolltech ASA.
怎么qmake的版本變成了qt3了,進入/usr/bin目錄下
- root@ubuntu:/home/yyy# cd /usr/bin
- root@ubuntu:/usr/bin# ls -l qmake
- lrwxrwxrwx 1 root root 23 2009-10-09 09:35 qmake -> /etc/alternatives/qmake
查看qmake的信息,它是一個鏈接指向的是/etc/alternatives/qmake
- root@ubuntu:/usr/bin# ls -l /etc/alternatives/qmake
- lrwxrwxrwx 1 root root 18 2009-12-08 12:46 /etc/alternatives/qmake -> /usr/bin/qmake-qt3
終于找到的根源,原來qmake被設置成了qmake-qt3
#p#
強行修改
- root@ubuntu:/usr/bin# rm /etc/alternatives/qmake
- root@ubuntu:/usr/bin# ln -s /usr/bin/qmake /etc/alternatives/qmake
- root@ubuntu:/usr/bin# qmake -v
- QMake version 2.01a
- Using QT version 4.5.0 in /usr/lib
5.安裝libmeegotouch
(1) 下載源代碼
- git clone git://gitorious.org/meegotouch/libmeegotouch.git
然后執行 chmod 777 -R libmeegotouch, 給下載下來的源碼全部加上最高權限
(2) 安裝一些依賴的庫。(根據個人PC的配置情況,以及后面2.4的配置結果,可能還需要安裝其他的一些依賴庫)
- sudo apt-get install libicu-dev graphviz
(3) 進入目錄libmeegotouch。
- cd libmeegotouch
(4) 進入目錄,生成makefile :
- qmake
(5) 執行make 編譯
- make
(6) 安裝
- sudo make install
在/usr/local/lib下的目錄,發現已經生成的MeeGo 庫文件
實踐:
1)寫一個hello world代碼
- main.cpp
- #include <MApplication>
- #include <MApplicationWindow>
- #include <MApplicationPage>
- #include <MLabel>
- int main(int argc, char **argv)
- {
- MApplication app(argc, argv);
- MApplicationWindow window;
- MApplicationPage page;
- page.setTitle("My First Page");
- page.setCentralWidget(new MLabel("Hello World!"));
- page.appear(&window);
- window.show();
- return app.exec();
- }
- HelloWorld.pro
- ######################################################################
- # Automatically generated by qmake (2.01a) ?? 9? 12 21:36:22 2010
- ######################################################################
- TEMPLATE = app
- TARGET =
- DEPENDPATH += .
- INCLUDEPATH += .
- CONFIG += meegotouch
- # Input
- SOURCES += main.cpp
如下圖:
生成makefile文件
- qmake
執行make
- make
運行程序 記得要加sudo
- sudo ./helloWorld
程序結果如下:
2) 編譯一個編譯example目錄里面的 tutorial_music_catalogue 例子
(1) tutorial_music_catalogue這個例子程序,有詳細的介紹文檔, 在libmeegotouch的文檔主頁上,有個介紹 Your first MeeGo Touch application ,適合做為入門文檔
(2) 由于libmeegotouch沒有安裝到標準路徑下,因此需要修改它的pro工程文件,打開文件 tutorial_music_catalogue.pro,在里面添加如下一段(如果meegotouch的安裝路徑不一樣,請自行對應修改):
- unix {
- INCLUDEPATH += /usr/local/include/meegotouch
- LIBS += -L/usr/local/lib -lmeegotouchcore -lmeegotouchextensions -lmeegotouchsettings -lmeegotouchviews
- QMAKE_LFLAGS += -Wl,-rpath,/usr/local/lib
- }
(3) 執行qmake
(4) 執行make,如果出現問題,可能是由于這個Makefile中需要調用mmoc。
- PATH=/usr/local/bin/:$PATH make
(5) 運行tutorial_music_catalogue
- sudo ./tutorial_music_catalogue
如果有花屏可以執行下面命令:
(并非所有的電腦都會黑屏或者花屏,所以運行程序的時候,可以自行嘗試一下不同的情況)
- sudo ./tutorial_music_catalogue -software
#p#
程序執行后的結果圖:
第一頁
第二頁
第三頁
(6) libmeegotouch程序通用的命令行參數。
- MComponentData: Usage: ./tutorial_music_catalogue
- [-software] Enable software rendering
- [-fullscreen] Make the application fullscreen
- [-show-br] Show the bounding rectangle for all scene items
- [-show-fps] Show the FPS for the view (only with OpenGL rendering)
- [-log-fps] Log the FPS for the application
- [-show-size] Show widget sizes in the scene
- [-show-object-names] Show the names of the objects in the scene
- [-show-position] Show widget positions in the scene
- [-show-cursor] Force the cursor to be visible
- [-reverse] Change the layout direction to right-to-left direction
- [-dev] Enable development visualization mode
- [-genimglist filename] Generate list of requested images to filename
- [-remote-theme] Wait until remote theme daemon is available
- [-local-theme] Force usage of local theme processing instead of remote theme daemon
- [-output-level debug|warning|critical] Only show messages of given output level or above
- [-output-prefix <prefix>] Only show debug messages that start with the given prefix
- [-no-output-prefix <prefix>] Only show debug messages that do not start with the given prefix
- [-target <name>] Use the target device profile
- [-prestart] Prestart the application (if supported)
- [-fixed-orientation 0|90|180|270] Start application in fixed orientation.
- This overrides keyboard state, as well as a device profile
(7) tutorial_music_catalogue這個示例程序很新,它依賴的QT版本和libmeegotouch版本,都高于目前MeeGo鏡像中對 應的QT和libmeegotouch版本,因此在開發板上或虛擬機里并不能運行。但是,不妨礙我們用它來學習入門。example目錄里面的其他示例程 序,在開發板上基本上都可以運行。
補充一些描述。
1 libmeegotouch是圖形開發工具箱,從它的功能上來說,它相當于QT,gtk,clutter等這一類圖形界面庫。
2 libmeegotouch是基于QT的,準確點說是基于QT的graphicsview框架的,但是,它在graphicsview的基礎上,又封裝出 一層widget。在使用方法上和設計模式上,和原始的graphicsview或qwidget,并沒有太多的交集。
3 開發MeeGo應用程序,如果沒有QT開發經驗,建議直接從libmeegotouch學起,在使用過程中,如果碰到了原始的QT中的class,再查閱 對應的手冊。這種學習路線,消耗的時間應該是最少的。
4 另外,雖然在PC上可以安裝libmeegotouch,但是這畢竟不是MeeGo的完整開發環境,它只負責MeeGo的GUI部分,因此這篇文檔介紹的 方法,不能替代MeeGo的完整開發環境。之所以在PC上安裝libmeegotouch,一方面是讓許多沒有硬件開發環境的朋友也可以在PC上體驗一下 MeeGo的界面操作方式,另一方面,也是想說明一下MeeGo程序在開發上的靈活性,比如前端UI設計的時候,就可以先在PC上做一些原型設計。
【編輯推薦】