顯示具有 Qt 標籤的文章。 顯示所有文章
顯示具有 Qt 標籤的文章。 顯示所有文章

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年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. 之前介紹的方法太過繁雜,此方法較為簡單。

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年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外面放開就會取消操作(不觸發事件)。

2009年12月10日 星期四

Qt Resource file

在Qt元件中如果只連結圖檔的話,compile並不會把圖檔包進來,(-static也一樣)
compile完後要是只抓執行檔出來就看不到連結的圖檔
必須要將圖檔放入Resource file中才行
步驟:
1. File -> New -> Qt Resource file -> OK
2. 輸入Name、Path(Resource file要存放的位置) -> Next
3. Finish
4. 點選新增的*.qrc
5. Add Prefix
6. Add files

2009年9月24日 星期四

ui

如要在.cpp中使用Qt Creater新建出來的元件
在使用的程式碼要用ui->元件名稱.......
如:在Qt Creater中拉出一個名叫Label_time的QLabel元件
要在Label_time中顯示"Hello"
程式碼要寫成:

ui -> Label_time -> setText("Hello");

2009年7月14日 星期二

Failure to open file: xxxxx/xxxxx/Makefile

the permission of the /opt directory was denied .....

save your project in your home directory

OpenGL缺少GL/gl.h

Compile OpenGL程式時缺少GL/gl.h時
安裝 libqglviewer-dev

2009年6月30日 星期二

"cannot find -lgobject-2.0" 錯誤訊息

發生 "cannot find -lgobject-2.0" 錯誤訊息

apt-get install libavahi-gobject-dev

安裝 libavahi-gobject-dev即可

"cannot find -lfreetype" 錯誤訊息

發生"cannot find -lfreetype" 錯誤訊息時

apt-get install libfreetype6-dev

安裝libfreetype6-dev即可

"g++:command not found" 錯誤訊息

build 出現"g++:command not found" 錯誤訊息,
可能為gcc未安裝

apt-get install g++ 即可

"No valid Qt version set. Set one in Tools/Options" 錯誤訊息

build時出現 "No valid Qt version set. Set one in Tools/Options" 錯誤訊息的解決方法:

1. 到 Tools → Options → Qt4 → Qt Versions
2. 在裡面新增一個 Qt Version
3. 指定Qt所安裝的路徑,如 "/opt/qtsdk-2009.03/qt"
4. Default Qt Version選擇剛才新增的 Version Name

重新開啟Qt即可

安裝QT 4.5.2

到QT官網下載

Qt SDK for Linux/X11 32-bit

安裝指令

chmod u+x qt-sdk-linux-x86-opensource-2009.03.bin (會依版本不同有所更動)
./qt-sdk-linux-x86-opensource-2009.03.bin (會依版本不同有所更動)

接下來跟著提示安裝即可