Adds Signals inheritance (#288)

* Inherit signals

* export signals

* Fix Qvariant build

* Adds Abstract button signals

* added more test cases
This commit is contained in:
Atul R
2019-12-20 23:48:53 +05:30
committed by GitHub
parent 01a6476f9c
commit 42e92ecbff
80 changed files with 401 additions and 191 deletions
@@ -107,7 +107,7 @@ public:
using QPushButton::QPushButton; //inherit all constructors of QPushButton
// override this method and implement all signals here
void connectWidgetSignalsToEventEmitter() {
void connectSignalsToEventEmitter() {
// Qt Connects: Implement all signal connects here
QObject::connect(this, &QPushButton::clicked, [=](bool checked) {
Napi::Env env = this->emitOnNode.Env();
@@ -145,4 +145,4 @@ We need to run Qt's MOC (Meta Object Compiler) on the file whenever we use Q_OBJ
1. On JS side for each widget instance we create an instance of NodeJS's Event Emitter. This is done by the class `EventWidget` from which `NodeWidget` inherits
2. We send this event emiiter's `emit` function to the C++ side by calling `initNodeEventEmitter` method and store a pointer to the event emitter's emit function using `emitOnNode`. initNodeEventEmitter function is added by a macro from EventWidget (c++). You can find the initNodeEventEmitter method with the event widget macros.
3. We setup Qt's connect method for all the signals that we want to listen to and call the emitOnNode (which is actually emit from Event emitter) whenever a signal arrives. This is done manually on every widget by overriding the method `connectWidgetSignalsToEventEmitter`. Check `npushbutton.h` for details. This takes care of all the signals of the widgets. Now to export all qt events of the widget, we had overriden the widgets `event(Event*)` method to listen to events received by the widget and send it to the event emitter. This is done inside the EVENTWIDGET_IMPLEMENTATIONS macro
3. We setup Qt's connect method for all the signals that we want to listen to and call the emitOnNode (which is actually emit from Event emitter) whenever a signal arrives. This is done manually on every widget by overriding the method `connectSignalsToEventEmitter`. Check `npushbutton.h` for details. This takes care of all the signals of the widgets. Now to export all qt events of the widget, we had overriden the widgets `event(Event*)` method to listen to events received by the widget and send it to the event emitter. This is done inside the EVENTWIDGET_IMPLEMENTATIONS macro