From f5b962f65b83363e2dd2b7e9d4bdfdd89ee8b117 Mon Sep 17 00:00:00 2001 From: Atul R Date: Sat, 8 Jun 2019 10:01:28 +0200 Subject: [PATCH] change to unique ptr still works -> but i beleive we have a memory leak now. --- .../QtWidgets/QMainWindow/qmainwindow_wrap.cpp | 2 +- src/cpp/QtWidgets/QPushButton/npushbutton.h | 18 +++++++++--------- .../QtWidgets/QPushButton/qpushbutton_wrap.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp index 6da4a6d90..5da28f3a1 100644 --- a/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp +++ b/src/cpp/QtWidgets/QMainWindow/qmainwindow_wrap.cpp @@ -23,7 +23,7 @@ NMainWindow* QMainWindowWrap::getInternalInstance() { QMainWindowWrap::QMainWindowWrap(const Napi::CallbackInfo& info): Napi::ObjectWrap(info) { Napi::Env env = info.Env(); Napi::HandleScope scope(env); - SuppressDestruct(); + // SuppressDestruct(); if(info.Length() == 1) { Napi::Object parentObject = info[0].As(); diff --git a/src/cpp/QtWidgets/QPushButton/npushbutton.h b/src/cpp/QtWidgets/QPushButton/npushbutton.h index 50fa6016c..0610af21d 100644 --- a/src/cpp/QtWidgets/QPushButton/npushbutton.h +++ b/src/cpp/QtWidgets/QPushButton/npushbutton.h @@ -10,7 +10,7 @@ class NPushButton: public QPushButton, public YogaWidget { private: - std::shared_ptr emitRef; + std::unique_ptr emitRef; public: SET_YOGA_WIDGET_Q_PROPERTIES using QPushButton::QPushButton; //inherit all constructors of QPushButton @@ -19,25 +19,25 @@ public: handleButton() )); } + ~NPushButton(){ + spdlog::info("DESTRUCTOR CALLED NPUSHBUTTON"); + this->emitRef.reset(); + } Q_OBJECT private slots: void handleButton(){ - emitRef->call([](Napi::Env env, std::vector& args) + emitRef->call([](Napi::Env env, std::vector& args) { // This will run in main thread and needs to construct the // arguments for the call args = { Napi::String::New(env, "clicked"), Napi::String::New(env, "YOLO") }; }); - spdlog::info("HANDLEBUTTON CALLED NPUSHBUTTON"); + spdlog::info("HANDLEBUTTON CALLED NPUSHBUTTON"); } public: - void setNodeEmitterEmit(std::shared_ptr emitterEmit){ - this->emitRef = emitterEmit; - } - ~NPushButton(){ - spdlog::info("DESTRUCTOR CALLED NPUSHBUTTON"); - this->emitRef.reset(); + void setNodeEmitterEmit( std::unique_ptr &emitterEmit){ + this->emitRef = std::move(emitterEmit); } }; diff --git a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h index a133cd63f..b0520e2fc 100644 --- a/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h +++ b/src/cpp/QtWidgets/QPushButton/qpushbutton_wrap.h @@ -20,9 +20,9 @@ class QPushButtonWrap : public Napi::ObjectWrap { Napi::Value setNodeEventEmiiter(const Napi::CallbackInfo& info) { Napi::Env env = info.Env(); - std::shared_ptr emitterEmit = std::make_shared(info[0].As()); + std::unique_ptr emitterEmit = std::make_unique(info[0].As()); this->instance->setNodeEmitterEmit(emitterEmit); - emitterEmit.reset(); + emitterEmit.release(); return env.Null(); }