Этот двигатель основан на Chomium, и все шло хорошо. Я могу открыть браузер Chromium в моем приложении QT Quick и получить доступ к любому веб -сайту.
Код: Выделить всё
[5524:22372:0209/133920.794:ERROR:html_media_element.cc(4888)] SetError: {code=4, message="MEDIA_ELEMENT_ERROR: Media load rejected by URL safety check"}Вот что я сделал:
1 - я добавил свой HTML -файл в раздел источников моих Cmakelists .txt: < /h1>
< /h1>
Код: Выделить всё
qt_add_qml_module(appSingerStudio
URI SingerStudio
VERSION 1.0
RESOURCES
qt-logo.png
SOURCES
ProjectManager.h
SettingsManager.h
html/index.html
html/script.js
html/styles.css
QML_FILES
Main.qml
Page.qml
Home.qml
ProjectPage.qml
ProjectCreation.qml
AudioPlayer.qml
LyricsEditor.qml
EditWebView.qml
)
< /code>
2 - Я изменил настройки конфигурации моего профиля хрома по умолчанию в моем main.cpp#< /h1>
#include
#include
#include
#include
#include
#include
#include
#include "ProjectManager.h"
#include "SettingsManager.h"
int main(int argc, char *argv[])
{
// Créer l'objet QApplication ou QGuiApplication en premier
QGuiApplication app(argc, argv);
// Initialiser WebEngine
QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessRemoteUrls, true);
QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::AllowRunningInsecureContent, true);
QWebEngineProfile::defaultProfile()->settings()->setAttribute(QWebEngineSettings::AllowGeolocationOnInsecureOrigins, true);
QtWebEngineQuick::initialize(); //I tried to initialize before and after but it doesn't matter
QQmlApplicationEngine engine;
SettingsManager settingsManager;
settingsManager.loadSettings();
ProjectManager projectManager(&settingsManager);
qmlRegisterSingletonInstance("com.example.settings", 1, 0, "SettingsManager", &settingsManager);
engine.rootContext()->setContextProperty("projectManager", &projectManager);
engine.rootContext()->setContextProperty("settingsManager", &settingsManager);
QObject::connect(
&engine,
&QQmlApplicationEngine::objectCreationFailed,
&app,
[]() { QCoreApplication::exit(-1); },
Qt::QueuedConnection);
engine.loadFromModule("SingerStudio", "Main");
// Lancer l'application
return app.exec();
}
< /code>
3 - я настроил URL в моем компоненте .qml:#< /h1>
import QtQuick
import QtWebEngine
WebEngineView {
anchors.fill: parent
url: "file:///" + Qt.resolvedUrl("html/index.html")
Component.onCompleted: {
console.log("URL loaded:", url);
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... -html-file
Мобильная версия