Created
January 12, 2015 10:20
-
-
Save Tosainu/24f9fd66dc28c987f836 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QMessageBox> | |
#include "jsobj.h" | |
JsObj::JsObj(QObject *parent) : QObject(parent) {} | |
void JsObj::hogeSlot() { | |
QMessageBox::information(nullptr, "JsObj::hogeSlot()", "Gochiusa!!"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef JSOBJ_H | |
#define JSOBJ_H | |
#include <QtCore> | |
class JsObj : public QObject { | |
Q_OBJECT | |
public: | |
JsObj(QObject *parent = nullptr); | |
public slots: | |
void hogeSlot(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QApplication> | |
#include "mainwindow.h" | |
auto main(int argc, char **argv) -> int { | |
QApplication app(argc, argv); | |
MainWindow window; | |
window.show(); | |
return app.exec(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtWebKitWidgets> | |
#include "mainwindow.h" | |
#include "jsobj.h" | |
MainWindow::MainWindow() { | |
auto jo = new JsObj(); | |
auto webview = new QWebView(this); | |
webview->setHtml(R"( | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<style> | |
html { | |
font: 16px/1.6 Roboto, 'Droid Sans', 'Hiragino Kaku Gothic ProN', sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Hello World!</h1> | |
<p>Tosainu likes <button onclick="jsobj.hogeSlot();">Click!</button></p> | |
</body> | |
</html> | |
)"); | |
webview->page()->mainFrame()->addToJavaScriptWindowObject("jsobj", jo); | |
this->setCentralWidget(webview); | |
} | |
MainWindow::~MainWindow() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef MAINWINDOW_H | |
#define MAINWINDOW_H | |
#include <QMainWindow> | |
class MainWindow : public QMainWindow { | |
Q_OBJECT | |
public: | |
MainWindow(); | |
~MainWindow(); | |
}; | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
QT += core gui webkitwidgets | |
TEMPLATE = app | |
TARGET = QWebView_html-to-cpp | |
INCLUDEPATH += . | |
HEADERS += mainwindow.h jsobj.h | |
SOURCES += main.cc mainwindow.cc jsobj.cc | |
CONFIG += c++11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment