Qt compiling map comprehensive application 57- cross platform (win, linux, mac, uos, kylin, etc.)

Posted by almora on Sun, 13 Feb 2022 03:11:49 +0100

1, Foreword

Cross platform really spent a lot of energy to start from Qt4 7 compatible to Qt6 2 and subsequent versions have lost a lot of hair, and only a few hairs are left. Hey, maybe this is the life of programmers. I have written Qt programs for so many years and prefer to support multiple Qt versions, especially for supporting any Qt version + any system + any compiler. This sentence is simple, but it is not easy to implement, First of all, you have to have many versions of the test environment, at least a dozen Qt environments, four or five operating systems, and install all kinds of VS versions. After all, in addition to the default mingw compiler, many people on win use msvc compiler. After all, it's not enough to have a 1T hard disk after so many environments, Moreover, the speed of releasing Qt version on the official website is quite fast. There must be one version in the slowest half a year, and it has to be tested again. Each time a large version is released, linux should be tested in addition to the commonly used windows, and now there are more domestic linux systems, such as deepin new start UOS. You should also try it. Alas, I'm so tired.

2, Functional features

1. Functional features of provincial and regional map encapsulation

  1. At the same time, it supports flashing point map, migration map, regional map, world map, dashboard, etc.
  2. You can set various colors such as title, prompt information, background color, text color, line color and area color.
  3. You can set the name, value, longitude and latitude set of the city.
  4. You can set the magnification of the map and whether to allow the mouse wheel to zoom.
  5. The built-in world map, national map, provincial map and regional map can be accurate to the county, and all maps can be used offline.
  6. Built in the function of converting json data files to js files in various provinces and cities. If there is data update, it can be converted by itself. It supports single file conversion and one click conversion of all files.
  7. The built-in function is to obtain all the names and longitude and latitude information sets of the area from json files or js files. The information can be obtained through this method for display.
  8. Rely on the browser component to display the map, and the demo provided supports WebKit / webengine / minilink / IE to load web pages.
  9. Using minilink browser kernel to get through Qt5 6 and subsequent versions + mingw compiler lacks browser module, which makes the whole project support all QT versions and test any version from 4.7 to 6.2.
  10. The set points such as flicker point migration diagram support setting the color separately.
  11. Provide an interface to directly obtain the relevant information of the click point, which is convenient for program linkage processing.
  12. It has strong expansibility. You can add all kinds of exquisite echarts components according to the gourd and gourd, and make an awesome effect.
  13. The built-in dashboard component provides interactive functions, and the corresponding code is included in the demo demonstration.
  14. The function interface is friendly and unified, simple and convenient to use, just one class.
  15. Support any Qt version, any system and any compiler.

2. Features of Baidu map encapsulation

  1. Both online map and offline map modes are supported.
  2. It also supports webkit kernel, webengine kernel, minilink kernel and IE kernel.
  3. Support the setting of multiple annotation points, including name, address, longitude and latitude.
  4. You can set whether the map can be clicked, dragged and zoomed with the mouse wheel.
  5. You can set the protocol version, secret key, theme style, central coordinate, central city, geocoding location, etc.
  6. You can set the zoom scale and level of the map, and the visibility of thumbnails, scale bars, road information and other controls.
  7. Support map interaction, such as pressing the mouse to obtain the longitude and latitude of the corresponding position.
  8. It supports route query, and can set the starting point location, terminal location, route mode, route mode and route scheme (minimum time, minimum transfer, minimum walking, no subway, minimum distance and avoiding high-speed).
  9. It can display point, line and surface tools, and can directly draw lines, dots, rectangles, circles, etc. on the map.
  10. You can set the administrative division, specify the drawing layer of a certain urban area, and automatically output the boundary points of the administrative division to the js file for the offline map.
  11. Multiple covers can be added statically or dynamically. Support point, polyline, polygon, rectangle, circle, arc, point aggregation, etc.
  12. Function interface is provided to process longitude and latitude resolution into address and address resolution into longitude and latitude coordinates.
  13. The provided demo can directly select points separately to perform corresponding processing, such as route query.
  14. You can get the point coordinate information set queried by the route, such as for robot coordinate navigation.
  15. It encapsulates rich functions, such as deleting specified points and all points, deleting specified covers and all covers, etc.
  16. The tagging point pop-up box information can be customized with standard html format.
  17. Mark point click event optional 0 - do not process 1 - pop up box 2 - send signal.
  18. Annotation points can be animated 0 - not processed 1 - jumping 2 - falling
  19. The marking points can be set to local picture files, etc.
  20. The function interface is friendly and unified, simple and convenient to use, just one class.
  21. Support js dynamic interactive adding points, deleting points, clearing points and resetting points without refreshing the page.
  22. Support any Qt version, any system and any compiler.

3. Features of offline map download

  1. Multi thread synchronous download of multi-level tile map without card interface.
  2. Multiple offline map download request addresses are built in, and one sending request is automatically selected at random.
  3. The download map type supports both street map and satellite map.
  4. Automatically calculate the number of downloaded tiles in the visual area or administrative area.
  5. The download level can customize the scope and selection.
  6. After each tile is downloaded, Chengdu sends a signal notification, and the parameters include the download time.
  7. The maximum download timeout can be set. If it exceeds, it will be discarded and jump to the next download task.
  8. The download progress, the number of tiles downloaded at the current level and the total number of tiles are displayed in real time.
  9. The download can be stopped during the download process, and the total time will be counted automatically after the download is completed.
  10. Built in longitude and latitude and screen coordinate conversion function.
  11. At present, baidu map is supported. Other maps such as Google map, Tencent map and Gaode map can be customized.
  12. The function interface is friendly and unified, simple and convenient to use, just one class.
  13. Support any Qt version, any system and any compiler.

4. Features of provincial and municipal Profile Download

  1. The timer queues up to download the point coordinate set of the provincial and municipal outline map and stores it in the JS file.
  2. It supports downloading from one administrative region to multiple irregular regions.
  3. Automatically calculate the number of downloaded profiles in the administrative region.
  4. You can accurately select provinces, urban areas and counties, or directly enter the name of administrative regions.
  5. You can set the download interval, start and stop downloading at any time.
  6. It provides the function of editing the boundary. You can directly edit the point set of irregular areas on the map, and then obtain the boundary point set data. This can be used to draw the area and get the data, such as the administrative area data of a township or even a community. It is very awesome.

3, Experience address

  1. Experience address: https://pan.baidu.com/s/1ZxG-oyUKe286LPMPxOrO2A Extraction code: o05q file name: bin_map.zip
  2. Domestic sites: https://gitee.com/feiyangqingyun
  3. International sites: https://github.com/feiyangqingyun
  4. Personal homepage: https://blog.csdn.net/feiyangqingyun
  5. Zhihu homepage: https://www.zhihu.com/people/feiyangqingyun/

4, Renderings

5, Related code

#include "webview.h"
#include "qevent.h"
#include "qdatetime.h"
#include "qdebug.h"

#ifdef webkit
#include <QtWebKit>
#include <QtWebKitWidgets>
#elif webengine
#include <QtWebEngineWidgets>
#elif webie
#include <QAxWidget>
#elif webminiblink
#include "miniblink.h"

#define TIMEMS qPrintable(QTime::currentTime().toString("HH:mm:ss zzz"))
WebView::WebView(QWidget *parent) : QObject(parent)
    //Initialize web control configuration information
    //Initialize universal map data

    //Data interaction class
    webJsData = new WebJsData(this);
    connect(webJsData, SIGNAL(receiveDataFromJs(QString, QVariant)),
            this, SIGNAL(receiveDataFromJs(QString, QVariant)));

#ifdef webkit
    webView = new QWebView(parent);
#elif webengine
    webView = new QWebEngineView(parent);
    //Set the corresponding communication channel
    QWebChannel *channel = new QWebChannel(this);
    channel->registerObject("objName", webJsData);
#elif webie
    webView = new QAxWidget(parent);
    //Register browser controls
    //Do not display warning messages
    webView->setProperty("DisplayAlerts", false);
    //Do not display scroll bar
    webView->setProperty("DisplayScrollBars", true);
#elif webminiblink
    webView = new miniblink(parent);

    //Associated load completion signal
#if (defined webkit) || (defined webengine)
    connect(webView->page(), SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
    connect(webView->page(), SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
#elif webminiblink
    connect(webView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
    connect(webView, SIGNAL(loadFinished(bool)), this, SIGNAL(loadFinished(bool)));
    connect(webView, SIGNAL(receiveDataFromJs(QString, QVariant)),
            this, SIGNAL(receiveDataFromJs(QString, QVariant)));

    //Setting has no right-click menu
#if (defined webkit) || (defined webengine) || (defined webie) || (defined webminiblink)

    //Install event filter
#ifdef webminiblink

void WebView::initWebSetting()
    //Global configuration only needs to be set once
    static bool isInit = false;
    if (!isInit) {
        isInit = true;
        QString webcore = "other";
#ifdef webkit
        webcore = "webkit";
        QWebSettings *webSetting = QWebSettings::globalSettings();
        webSetting->setAttribute(QWebSettings::JavascriptEnabled, true);
        webSetting->setAttribute(QWebSettings::PluginsEnabled, true);
        webSetting->setAttribute(QWebSettings::JavascriptCanOpenWindows, true);
#elif webengine
        webcore = "webengine";
        QWebEngineSettings *webSetting = QWebEngineProfile::defaultProfile()->settings();
        webSetting->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
        webSetting->setAttribute(QWebEngineSettings::PluginsEnabled, true);
        webSetting->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);
#elif webie
        webcore = "ie";
#elif webminiblink
        webcore = "miniblink";
        qDebug() << TIMEMS << QString("init webview ok, core: %1").arg(webcore);

bool WebView::eventFilter(QObject *watched, QEvent *event)
    //The test found that the minilink kernel (other kernels are normal), and the right button in the web page will send a message to the parent class
    if (event->type() == QEvent::MouseButtonPress) {
        return true;
    return QObject::eventFilter(watched, event);

void WebView::setLayout(QLayout *layout)
    //Add control to layout
#if (defined webkit) || (defined webengine) || (defined webie) || (defined webminiblink)

void WebView::setVisible(bool visible)
#if (defined webkit) || (defined webengine) || (defined webie) || (defined webminiblink)

void WebView::setBgColor(const QColor &color)
#if (defined webkit) || (defined webie)
#elif (defined webengine)
#elif (defined webminiblink)

void WebView::loadFinished()
#ifdef webkit
    webView->page()->mainFrame()->addToJavaScriptWindowObject("objName", webJsData);

void WebView::load(const QString &url, const QString &html, const QString &baseUrl)
    //If there is a web address, it is preferred to load the web address directly
    if (!url.isEmpty()) {
#if (defined webkit) || (defined webengine)
#elif webie
        webView->dynamicCall("Navigate(const QString&)", url);
#elif webminiblink
    } else {
#if (defined webkit) || (defined webengine)
        webView->setHtml(html, QUrl(baseUrl));
#elif webminiblink
        webView->setHtml(html, baseUrl);

void WebView::runJs(const QString &js)
    if (js.isEmpty()) {
#ifdef webkit
#elif webengine
#elif webminiblink

Topics: Linux Qt macOS