Linux 2009-03-11 15:34:53 閱讀150 評論0 字號:大中小
bt3環(huán)境下使用 Qt 4.4.0 中的QWebView控件(WebKit引擎)
/* 下載安裝 */
一、安裝QT 4.4.0
下載
ftp://ftp.trolltech.no/qt/source/qt-x11-opensource-src-4.4.0.tar.gz
解壓
tar -zxvf qt-x11-opensource-src-4.4.0.tar.gz
進入已解壓文件夾
cd qt-x11-opensource-src-4.4.0.tar.gz
配置
./configure -prefix /opt/qt-4.4.0 -release -shared -fast -system-sqlite -no-openssl -nomake examples -nomake demos -optimized-qmake -no-nis -no-cups -no-separate-debug-info
/* http://blog.chinaunix.net/u2/86537/showart_1716377.html */
編譯
gmake
安裝
gmake install
二、設置環(huán)境變量與不改以前的gmake
1)修改QT4環(huán)境變量,主要是二個,一是頭文件include,二是可執(zhí)行文件bin.
QTDIR="opt/qt-4.4.0"
PATH="$QTDIR/bin:$PATH"
export QTDIR PATH
CPLUS_INCLUDE_PATH="$QTDIR/include:$CPLUS_INCLUDE_PATH"
export CPLUS_INCLUDE_PATH
/* 創(chuàng)建Qt程序 */
三、新建main.cpp文件
1)QMainWindow
#include "ui_main.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
QMainWindow *form = new QMainWindow;
Ui::MainWindow ui;
ui.setupUi(form);
form->show();
form->showMaximized(); // Max Show
return a.exec();
}
2)QWidget 一般都用這個,因為QWidget是父類
#include "ui_main.h"
int main( int argc, char ** argv )
{
QApplication a( argc, argv );
QWidget *form = new QWidget(0,Qt::Widget);
Ui::Form ui;
ui.setupUi(form);
form->show();
form->showMaximized(); // Max Show
return a.exec();
}
二、編譯與生成
1)新建界面*.ui
2)生成工程文件,/opt/qt-4.4.0/bin/qmake -project
3)生成Makefile文件,/opt/qt-4.4.0/bin/qmake -o Makefile a.pro(或者直接qmake)
4)生成可執(zhí)行文件,make
三、如何成功編譯QWebView控件(WebKit引擎)
在使用QWebView控件時可能會遇到二個錯誤
1)錯誤一
/opt/qt-4.4.0/include/QtWebKit/qwebsettings.h:23:27: error: qwebkitglobal.h: No such file or directory
解答:
將qwebsettings.h里的<qwebkitglobal.h>變成"qwebkitglobal.h"即可;
2)錯誤二
undefined reference to 'QWebView::QWebView(QWidget*)'
解答:
用記事本打開工程文件*.pro加入 QT += webkit;
注意:
如果把編譯好的可執(zhí)行文件,拷貝到另一個linux系統(tǒng)使用,不能運行,
要把源代碼拷貝過去,重新編譯才能啊
打開網(wǎng)站
QWebView *web = new QWebView(NULL);
web->setUrl( QUrl("http://maps.google.com/") );
web->show();
QWebView *web = new QWebView(NULL);
web->load( QUrl("http://maps.google.com/") );
web->show();
QWebView使用說明
http://doc.trolltech.com/main-snapshot/qwebview.html
http://doc.trolltech.com/qtjambi-4.4/html/com/trolltech/qt/webkit/QWebView.html
GMap網(wǎng)址
http://maps.forum.nu/gm_mouse_wheel_zoom.html