I have been unable to find a definitive answer to my problem.
I currently have a QWebView control load an html file that is on my hard-drive, that implements a vector map with javascript actions. The html file loads a jvectormap US States Map. The click action on any state fires the onRegionClick action that is tied to the showCities function, which the event and code arguments are handled by the onRegionClick method implemented in the jquery-jvectormap.js file. The html file follows:
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="styles/style2.css" type="text/css"/>
<link rel="stylesheet" media="all" href="styles/jquery-jvectormap.css"/>
<script src="js/jquery.tools.min.js"></script>
<script src="js/jquery-jvectormap.js"></script>
<script src="js/jquery-jvectormap-us-en.js"></script>
<script>
$(function() {
$('.map').vectorMap({
map: 'us_en',
color: 'green',
hoverColor: 'blue',
onRegionClick: showCities
});
});
function showCities(event, code) {
return code;
}
</script>
</head>
<body>
<div id="front">
<div class="map"></div>
</div>
</body>
</html>
And the mainwindow.h header file information in Qt:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QUrl>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_webView_linkClicked(const QUrl &arg1);
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
And then the MainWindow.cpp file:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QtGui>
#include <QtCore>
#include <QDebug>
#include <QtWebKit>
#include <QWebSettings>
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->webView->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
ui->webView->settings()->setAttribute(QWebSettings::JavascriptEnabled, true);
connect(ui->webView,SIGNAL(linkClicked(QUrl)),this,SLOT(on_webView_linkClicked(QUrl)));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_webView_linkClicked(const QUrl &arg1)
{
QMessageBox::information(this,"Title","Test");
}
The on_webView_linkClicked function is not being triggered/fired when I click on any particular region area. Any region clicked is designed to return a string. When I try this on a webpage, like http://www.google.com, the QMessageBox in the on_WebView_linkClicked function actually triggers/fires an event that shows the QMessageBox.
The goal here is to get the javascript string returned in the html file in the function showCities to show up in the on_webView_linkClicked event. Apparently, the linkClicked action is not recognizing the javascript return as a link, so it remains silent when using the jquery vector map.
I have searched everywhere for this, and the only answer I can get is that if those regions in the vectormap had url links attached to them, it might work, but my embedding dummy links in those regions does not cause the on_webView_linkClicked event to fire.
Thank you for all your help :)
IMHO, the follow solution is simpler:
mainwindow.h
mainwindow.cpp
abc.js
You can inject a QObject (e.g. your MainWindow) into a JavaScript. Once your JavaScript function is called, you can transfer that call to the injected object.
Not a complete code, but to give an idea:
MainWindow.h
MainWindow.cpp
in HTML JS