diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.cpp b/src/QtLocationPlugin/QGCTileCacheWorker.cpp index eca022cbe848d923d1ed5a1e2ca9a962cad391de..a65ab83b9cb8451f6fd4f86aa0d243fa8ecea7dd 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.cpp +++ b/src/QtLocationPlugin/QGCTileCacheWorker.cpp @@ -73,6 +73,9 @@ QGCCacheWorker::setDatabaseFile(const QString& path) void QGCCacheWorker::quit() { + if(_hostLookupID) { + QHostInfo::abortHostLookup(_hostLookupID); + } _mutex.lock(); while(_taskQueue.count()) { QGCMapTask* task = _taskQueue.dequeue(); @@ -1055,12 +1058,24 @@ QGCCacheWorker::_createDB(QSqlDatabase* db, bool createDefault) void QGCCacheWorker::_testInternet() { - QTcpSocket socket; - socket.connectToHost("www.github.com", 80); - if (socket.waitForConnected(2500)) { - qCDebug(QGCTileCacheLog) << "Yes Internet Access"; - emit internetStatus(true); - return; + if(!_hostLookupID) { + _hostLookupID = QHostInfo::lookupHost("www.github.com", this, SLOT(_lookupReady(QHostInfo))); + } +} + +//----------------------------------------------------------------------------- +void +QGCCacheWorker::_lookupReady(QHostInfo info) +{ + _hostLookupID = 0; + if(info.error() == QHostInfo::NoError && info.addresses().size()) { + QTcpSocket socket; + socket.connectToHost(info.addresses().first(), 80); + if (socket.waitForConnected(2000)) { + qCDebug(QGCTileCacheLog) << "Yes Internet Access"; + emit internetStatus(true); + return; + } } qWarning() << "No Internet Access"; emit internetStatus(false); diff --git a/src/QtLocationPlugin/QGCTileCacheWorker.h b/src/QtLocationPlugin/QGCTileCacheWorker.h index d53f5ba977caf8e0228e8b7e58a7a79248d6d34d..a46a91117edc378c2cae604a8ae23b0833d6e759 100644 --- a/src/QtLocationPlugin/QGCTileCacheWorker.h +++ b/src/QtLocationPlugin/QGCTileCacheWorker.h @@ -26,6 +26,7 @@ #include #include #include +#include #include "QGCLoggingCategory.h" @@ -49,6 +50,9 @@ public: protected: void run (); +private slots: + void _lookupReady (QHostInfo info); + private: void _saveTile (QGCMapTask* mtask); void _getTile (QGCMapTask* mtask); @@ -93,6 +97,7 @@ private: quint32 _defaultCount; time_t _lastUpdate; int _updateTimeout; + int _hostLookupID; }; #endif // QGC_TILE_CACHE_WORKER_H