QWebEngineView display white screen

67 Views Asked by At

I'm trying to add a map to my application via leaflet in Qt6, but when I use WebEngine and open local html, it only shows a white screen. If I run this page in a normal browser, everything works fine. What is the problem?

Mainwindow.cpp:

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Создание модели списка изображений
    imageListModel = new QStringListModel(this);
    ui->SelectedImagesList->setModel(imageListModel);

    QWebEngineView* webView = new QWebEngineView(ui->MapViewFake);
    QUrl url = QUrl("qrc:///map/index.html");


    webView->setGeometry(150, 10, 991, 611);

}

Ui: enter image description here

Html:

// Создание карты и установка начальных координат и масштаба
var map = L.map('map').setView([51.505, -0.09], 13);

// Добавление слоя OpenStreetMap
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
    attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">OpenStreetMap</a> contributors',
    maxZoom: 18,
}).addTo(map);
body {
    padding: 0;
    margin: 0;
}
html, body, #map {
    height: 100%;
    width: 100%;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Map</title>

    <link rel="stylesheet" href="style.css"/>
    <link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin="" />
    <script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
</head>
<body>
    <div id="map"></div>

    <script src="index.js"></script>
</body>
</html>

Result: enter image description here

0

There are 0 best solutions below