This is a sample project that integrates Qt's Meta Object System with CEF. (Only Tested under Linux)
-
Supports passing any JSON stringifiable JS value to C++, namely
- number (C++ number types(int, uint, float, double, etc), or the corresponding C++ enum member)
- string (QString)
- null (empty QVariantMap)
- undefined (empty QVariantMap)
- array (QVariantList, or QStringList)
- boolean (C++ bool)
- object (QVariantMap)
-
Supports overloaded Qt slots.
-
Requires greater type strictness than Qt WebKit; not as many implicit-cast as Qt WebKit.
For example, Javascript number
1
is not considered C++ booleantrue
, and such attempt will result in promise's rejection on the JS side. However if this behavior is very desired, you can implement it incg.js
fairly easily. -
Wraps Qt Slot calls with ES6 Promises.
-
Wraps Qt Signal emissions with event handlers.
-
C++ enums are partially supported. See Limitations below.
-
The webview's
bridge
(orchannel
you may call), must be able to be compiled alone, without the WebView. This is because in this implementation, thebridge
's meta information is determined before compile-time, instead of run-time. -
You'll need to manually name all relevant C++ enums in
cg.js
. -
Class forward cannot be used in
bridge.h
, if you have a QObject under the entranceBridge
object. -
Assumes all Qt slots' invocation happens on the CEF's BrowserProcess.
-
Generate a file describing
bridge
's structure.Compile CMake target
QtMoExtractor
, and runmkdir QtSample/cg ./QtMoExtractor > QtSample/cg/Bridge.def
-
Generate the codes that bridges Qt and CEF
cd QtSample node --harmony --harmony_destructuring ./cg.js
-
Compile CMake target
Application
-
Run
./Application --no-sandbox
- CEF >= Branch 2623, equivalent to Chrome 49
- C++14 compiler (With a few tweaks, this can be relaxed to C++11)
- Recent versions of NodeJS
- Qt5
Do whatever you want with it.