2010年12月24日 星期五

Qt Webkit demo

#include
#include
#include
#include

int main(int argc, char *argv[]){
QApplication a(argc, argv);
QWebView *view = new QWebView(0);
view->page()->mainFrame()->setScrollBarPolicy(Qt::Horizontal,Qt::ScrollBarAlwaysOff);
view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
view->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
view->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
view->settings()->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
view->load(QUrl("http://www.google.com.tw/"));
//view->load(QUrl("http://tw.yahoo.com/"));
view->setWindowTitle("hello QtWebKit");
view->show();
return a.exec();
}

修改.pro文件,加入:QT +=webkit

2010年12月9日 星期四

google好手氣

原來google好手氣可以這樣用
在支援網址列搜尋的瀏覽器(如sleipnir、opera、lunascape...等)中設定以
http://www.google.com.tw/search?btnI=I%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q=
當作搜尋引擎
只要在網址列打上要打開網站的關鍵字(如yahoo、mobile01)
就可以直接進入該網站了
對我這樣的懶人來說超方便的^^b

2010年11月24日 星期三

在Linux系統讓Qt 讀取經由 Bluetooth spp傳進來的資料流

以Ubuntu為例

1. 先以 bluez 配對。

2. 下 hcitool scan 指令,取得欲連線設備的 BD Address (本例為 00:0E:00:05:63:20)。

3. 下 rfcomm connect 0 00:0E:00:05:63:20 1 指令連結設備的spp profile,連結成功即會在/dev中產生一個device file,名為 rfcomm0。

4. 連結成功後可用
  • cat /dev/rfcomm0 od -c 或
  • hexdump /dev/rfcomm0

測試是否可讀取。

5. 之後即可在Qt中使用qextserialport做處理。

6. rfcomm release 0 指令可釋放 rfcomm0 device 。

ps. 之前介紹的方法太過繁雜,此方法較為簡單。

在VirtualBox的Ubuntu掛載檔案分享

1. 先在Windows裡的VirtualBox設定欲分享的資料夾(本例為share)
2. 在Ubuntu的桌面建立新資料夾(本例為/home/denver/桌面/share)
3. 下指令:sudo mount -t vboxsf 分享資料夾名稱 掛載路徑 。
例:sudo mount -t vboxsf share /home/denver/桌面/share。
4. 之後即可在兩個os中使用此資料夾互通檔案。

2010年11月18日 星期四

qextserialport的用法(Linux)

1. 至sourceforge下載 source code (qextserialport-1.2win-alpha.zip),並解壓縮。

2. 將
  • posix_qextserialport.h
  • posix_qextserialport.cpp
  • qextserialbase.h
  • qextserialbase.cpp

四個檔案加入專案中。

3. 在專案主程式標頭檔中加入 #include posix_qextserialport.h

4. 之後即可在主程式中使用qextserialport函式。

EX:

1. 在主程式標頭檔中的 private: 中加入宣告

  • Posix_QextSerialPort *myCom;

2. 在主程式中加入Serial Port控制設定:
  • myCom = new Posix_QextSerialPort(SerialPort, QextSerialBase::Polling);
  • myCom -> open(QIODevice::ReadWrite);
  • myCom -> setBaudRate(BAUD9600);
  • myCom -> setDataBits(DATA_8);
  • myCom -> setParity(PAR_NONE);
  • myCom -> setStopBits(STOP_1);
  • myCom -> setFlowControl(FLOW_OFF);
  • myCom -> setTimeout(10);

3. 宣告 QByteArray message = myCom -> readAll().toHex(); 讀進來之數據會存於message變數中,可依需求作處理。

※Linux只能使用Polling的方式。

※SerialPort為/dev/中Serial Port的device file name

※以Linux為例:

  • pl2303 USB轉RS232之device file name為ttyUSB0、ttyUSB1、ttyUSB2.....
  • bluetooth spp之device file name為rfcomm0、rfcomm1、rfcomm2.....

※timeout要設短一點,如:myCom->setTimeout(10);

在windows 7下手動安裝qt 4.7.1

為了使用 static compile,所以 Qt 使用 MinGW 自行 make,Qt Creator IDE 則使用官網下載的 windows binary 安裝,再設定好 qmake 的位置即可。

1. 下載各個所需的檔案:

  • mingw-get-inst-20101030.exe
  • qt-everywhere-opensource-src-4.7.1.tar.gz
  • qt-creator-win-opensource-2.0.1.exe

2. 先安裝好 MinGW 與 Qt Creator IDE。

3. 在 windows 的環境變數中加入使用者變數 PATH,值為:C:\MinGW\bin;C:\MinGW\include;C:\MinGW\lib;D:\Qt\4.7.1\bin (請依自己系統環境設定)

4. 將 qt-everywhere-opensource-src-4.7.1.tar.gz 解壓縮到欲安裝的位置 (本例為 D:\Qt\4.7.1\bin ),並進入此資料夾。

5. 下指令 configure -debug-and-release -opensource -static -platform win32-g++ (參數請依需自行加入、設定)

6. configure 完成後下指令 mingw32-make。

7. make 完成後打開 Qt Creator,在 Tools → Options → Qt4 → Qt Versions 中加入自行 make 的 qmake位置路徑,完成後即可使用。

2010年9月28日 星期二

在Ubuntu安裝Qt前請先安裝下面幾個開發工具包

在Ubuntu安裝Qt前請先安裝下面幾個開發工具包
  • libX11-dev
  • libXext-dev
  • libXtst-dev
  • libqglviewer-dev
  • libmysql++-dev
  • g++

2010年8月3日 星期二

cat /dev/rfcomm0 | od -c

hexdump /dev/rfcomm0

可用來讀取 rfcomm0 的數據 (16進位碼)


2010年4月14日 星期三

刪除GRUB選單裡舊kernel選項

隨著Ubuntu的kernel更新,GRUB選單的選項會越來越多
我們可以刪除GRUB選單裡舊kernel選項:

1. 使用synaptic移除
  • linux-headers-x.x.xx-xx
  • linux-headers-x.x.xx-xx-generic
  • linux-image-x.x.xx-xx-generic
2. sudo update-grub2

2010年4月13日 星期二

ubuntu ssh server簡易安裝

1. 在synaptic中找尋,並安裝ssh套件
2. 修改 /etc/ssh/ssh_config
3. 將 # port 22 中的# 去掉,並修改要使用的port number
4. 如有修改port number,需將 /etc/sshsshd_config 之port number也改掉
5. reboot

2010年1月28日 星期四

Qt 4.7.2 手動安裝

0. 如是新安裝,請先裝 libX11-dev、libXext-dev、libXtst-dev、libqglviewer-dev、libmysql++-dev、g++開發工具包。

1. 至NOKIA FTP 下載 qt-everywhere-opensource-src-4.7.2.tar.gz

2. 解壓縮,並進入解壓縮後的資料夾

3. ./configure -static -debug-and-release -qt-sql-mysql -qt-libpng -qt-libjpeg -qt-gif -opengl -prefix /opt/qt-4.7.2-static

4. make

5. sudo make install


順便安裝qtcreator 2.1.0

1. 下載 qt-creator-linux-x86-opensource-2.1.0.bin

2. sudo chmod u+x qt-creator-linux-x86-opensource-2.1.0.bin

3. sudo ./qt-creator-linux-x86-opensource-2.1.0.bin

4. 安裝完成後,在qt versions裡的qmake location新增設定Qt 4.7.2的位置,並Rebuild Debugging Helper。

5. 如果之前有project,記得調整projects中的build configuration及qt versions參數。


2010年1月27日 星期三

"serif" or "sans serif"

serif主要使用在內文,而sans serif主要使用在比較醒目的地方,且較適合橫排中文。
李果正前輩在他的部落格有比較詳盡的解說:
http://blog.bs2.to/post/EdwardLee/3401

2010年1月13日 星期三

mouse pressed() 與 clicked() 的區別

pressed()
是只要在button上按下滑鼠鍵後馬上就會觸發事件。

clicked()
則必須要滑鼠在button上按下並放開滑鼠鍵才會觸發事件,亦即press與release後才會觸發事件。
使用者在button上按下滑鼠鍵後改變了主意,則移動到button外面放開就會取消操作(不觸發事件)。

2010年1月12日 星期二

Linux下如何用Bluetooth與設備建立SPP(Serial Port Profile)連線

以Ubuntu 9.04為例
1. 先使用BlueZ與設備配對

2. # hciconfig -a 取得Bluetooth dongle的BD Address
# hcitool dev 也可以取得BD Address
我的Bluetooth dongle是00:10:60:A4:12:F1

3. 下hcitool scan指令,取得欲連線設備的BD Address
  我的欲連線設備是00:0E:00:05:63:20

4. # mknod /dev/rfcomm0 c 216 1
# chmod 666 /dev/rfcomm0 建立虛擬串口設備,並設定權限

5. 修改/etc/bluetooth/rfcomm.conf設定檔,加入以下內容:
# vi /etc/bluetooth/rfcomm.conf

rfcomm0{
bind no; //設置是否自動綁定設備
device 00:10:60:A4:12:F1; //設定綁定設備的BD Address(Bluetooth dongle)
channel 1; //設定設備通道
comment "BTM"; //對設備的描述
}

6. 添加SPP(Serial Port Profile)的SDP協議通道
# sdptool add --channel=1 SP

7. 將虛擬串口與外界藍芽設備綁定
  # rfcomm bind /dev/rfcomm0 00:0E:00:05:63:20 1  

8. 連接設備
  # hcitool cc 00:0E:00:05:63:20

9. 之後就可以利用GtkTerm或是minicom測試連線是否成功