我使用QWebView显示加载谷歌地图的简单html页面。但是当拖动地图时,加载图像的速度确实很慢,并且看起来它似乎没有缓存它们,因为它第二次移动也慢了。
有人看过类似的东西,并得到了解决方案吗?
#define MAP_HTML "<html><head><script type=\"text/javascript\" " \
"src=\"http://maps.googleapis.com/maps/api/js?sensor=false\"></script>" \
"<script type=\"text/javascript\">" \
"var map; function initialize(lat, lng) { "\
"map = new google.maps.Map(document.getElementById(\"map_canvas\"), " \
"{ zoom: 15, center: new google.maps.LatLng(lat, lng), " \
"disableDefaultUI: true, mapTypeId: google.maps.MapTypeId.ROADMAP });" \
"} </script>" \
"</head><body style=\"margin:0px; padding:0px;\" onload=\"initialize(55.786033,12.521667)\">" \
"<div id=\"map_canvas\" style=\"width:100%; height:100%\"></div>" \
"</body></html>"
GMapWidget::GMapWidget(QWidget *parent)
: QWebView(parent)
, m_accessManager(new QNetworkAccessManager(this))
, m_initMap(false)
{
connect(m_accessManager, SIGNAL(finished(QNetworkReply*)), this, SLOT(slotNetworkReply(QNetworkReply*)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
setHtml(MAP_HTML);
// auto t = QUrl::fromLocalFile("index.html").path();
// load(QUrl::fromLocalFile("index.html"));
}
答案 0 :(得分:1)
您可以尝试向QNetworkDiskCache
添加QNetworkAccessManager
,看看它是否更好:
QNetworkDiskCache *diskCache = new QNetworkDiskCache(this);
diskCache->setCacheDirectory("cacheDir");
m_accessManager->setCache(diskCache);