因爲QT版本更新,QT裏面的WebView控件找不到了,不過經過查找一些資料和本身的摸索,終於明白如何使用QT裏面的AxWidget去替換WebView。html
首先在UI裏面添加一個QAxWidget的控件拉到UI上面去web
QAxWidget:api
作好這步之後還須要將你的QAxWidget提高爲WebQAxWidget這時候基本搞定了UI設計的控件要求
下面是我製做的的一個地圖顯示的源代碼
ide
#include "map.h"網站
#include "ui_map.h"ui
#include "QApplication"this
#include "QListWidgetItem"url
#include "QListWidget"spa
#include "QMessageBox"設計
#include "QDir"
#include "QFileDialog"
#include "QFile"
#include "QListWidgetItem"
#include "QDebug"
#include "QVariant"
#include "QAbstractEventDispatcher"
#include "QUrl"
#include "QNetworkAccessManager"
#include "QNetworkRequest"
#include "QNetworkReply"
#include "QUrlQuery"
#include "QtNetwork"
#include "QDesktopWidget"
#include "QHttpPart"
#include "QFrame"
Map::Map(QWidget *parent) :
QWidget(parent),
ui(new Ui::Map)
{
ui->setupUi(this);
setWindowTitle("Map");
setMaximumHeight(408);
setMinimumHeight(408);
setMaximumWidth(399);
setMinimumWidth(399);
//ui->addrLineEdit->setText("https://www.baidu.com/");
this->showBaiduMap();
connect(ui->goCityBtn,SIGNAL(clicked(bool)),this,SLOT(showAddrWeb()));
connect(ui->mapBtn,SIGNAL(clicked(bool)),this,SLOT(showBaiduMap()));
connect(ui->DispalyThething,SIGNAL(clicked(bool)),this,SLOT(ShowDataMapSlots()));
}
Map::~Map()
{
delete ui;
}
void Map::webShow(const QString &url)
{
ui->webBrowser->dynamicCall("Navigate(const QString&)",url); //打開一個網站在webBrower控件內
}
void Map::showAddrWeb()
{
QString addr=ui->addrLineEdit->text();
//if((addr.indexOf("www")!=0)&&(addr.indexOf("http")!=0)) return;
webShow(addr);
}
void Map::showBaiduMap()
{
QString mapHtml=QDir::currentPath()+"/MapFile/BaiduMap.html";
qDebug()<<QDir::currentPath();
//qDebug()<<myurl;
//ui->addrLineEdit->setText("地圖");
webShow(mapHtml);
}
void Map::ShowDataMapSlots()
{
}
/*
QUrl Map::GPSMark(const QString &GPSCoordinate)
{
QUrl temp;
QString ret;
HttpClient * http = new HttpClient();
QUrl url;
url.setUrl("http://api.map.baidu.com/marker");
QUrlQuery urlQuery;
urlQuery.addQueryItem("location", GPSCoordinate);
urlQuery.addQueryItem("title", tr("my GPS location")); //標點的標題
urlQuery.addQueryItem("content", tr("current location")); //標點的內容
urlQuery.addQueryItem("output", "html");
urlQuery.addQueryItem("coord_type", "bd09");
urlQuery.addQueryItem("src", "map");
url.setQuery(urlQuery);
http://map.baidu.com/?latlng=40.047669,116.313082&title=my gps loclation
url = QUrl("http://map.baidu.com/?latlng=40.047669,116.313082&title=個人位置&content=百度奎科大廈&autoOpen=true&l");
webShow(url);
setWindowTitle(url.toString());
return temp;
}*/