Using googlemap with QWebEngineView, i would like to add myscript.js in the html file. It works very well in debug, but not in release. In release mode, myscript.js is not found with error js: Uncaught (in promise) ReferenceError: myscriptNameSpace is not defined
I'm working with Qt 5.12.2, MSVC 2017
my qrc file
<RCC>
<qresource prefix="/">
<file>html/googlemap.html</file>
<file>js/myscript.js</file>
</qresource>
</RCC>
my .h file
class GoogleMapWebEngine : public QWidget
{
Q_OBJECT
public:
explicit GoogleMapWebEngine(QWidget *parent = nullptr);
virtual ~GoogleMapWebEngine() override;
protected:
virtual void wheelEvent(QWheelEvent * event) override;
private:
Ui::GoogleMapWebEngine *ui;
QWebEngineView* m_webview;
QWebChannel* m_webChannel;
};
my .cpp file
GoogleMapWebEngine::GoogleMapWebEngine(QWidget *parent) :
QWidget(parent),
ui(new Ui::GoogleMapWebEngine)
{
qputenv("QTWEBENGINE_REMOTE_DEBUGGING", "1234");
ui->setupUi(this);
m_webview = new QWebEngineView();
m_webChannel = new QWebChannel();
m_webChannel->registerObject("goolemainWindow", this);
m_webview->page()->setWebChannel(m_webChannel);
QUrl url = QUrl("qrc:/html/googlemap.html");
m_webview->setUrl(url);
ui->verticalLayout->addWidget(m_webview);
}
my googlemap.html file
<html>
<head>
...
<script src="qrc:/js/myscript.js"></script>
<script type="text/javascript">
function initMap()
{
var
mapCenter = [32.794488, -96.780372],
mapOptions = {
zoom: 18,
center: new google.maps.LatLng(mapCenter[0], mapCenter[1]),
mapTypeId: google.maps.MapTypeId.SATELLITE
},
map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
myscriptNameSpace.test();
}
</script>
</head>
<body ondragstart="return false">
<div id="map-canvas" />
<script async defer src="https://maps.googleapis.com/maps/api/js?key=myKey&callback=initMap"></script>
</body>
</html>
myscript.js
var myscriptNameSpace = {}
myscriptNameSpace.test = function(){
alert('test');
}
Expected : Alert message must be displayed
Current error : js: Uncaught (in promise) ReferenceError: myscriptNameSpace is not defined
My full source code is found here : github.com/hunglxtp/googlemapTest