From b8b3dd53e7ec60a6b8caece1e80b990a9529b115 Mon Sep 17 00:00:00 2001 From: Atul R Date: Fri, 12 Jul 2019 20:25:15 +0200 Subject: [PATCH] add set text on radio button --- src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp | 12 ++++++++++++ src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h | 1 + src/lib/QtWidgets/QRadioButton/index.ts | 4 ++++ 3 files changed, 17 insertions(+) diff --git a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp index 8fde84389..e91eafd03 100644 --- a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp +++ b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.cpp @@ -11,6 +11,7 @@ Napi::Object QRadioButtonWrap::init(Napi::Env env, Napi::Object exports) { Napi::HandleScope scope(env); char CLASSNAME[] = "QRadioButton"; Napi::Function func = DefineClass(env, CLASSNAME, { + InstanceMethod("setText", &QRadioButtonWrap::setText), QWIDGET_WRAPPED_METHODS_EXPORT_DEFINE(QRadioButtonWrap) }); constructor = Napi::Persistent(func); @@ -43,3 +44,14 @@ QRadioButtonWrap::~QRadioButtonWrap() { delete this->instance; } +Napi::Value QRadioButtonWrap::setText(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + Napi::HandleScope scope(env); + + Napi::String napiText = info[0].As(); + std::string text = napiText.Utf8Value(); + this->instance->setText(text.c_str()); + return env.Null(); +} + + \ No newline at end of file diff --git a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h index 49fa54f16..fdb380fb8 100644 --- a/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h +++ b/src/cpp/QtWidgets/QRadioButton/qradiobutton_wrap.h @@ -16,6 +16,7 @@ class QRadioButtonWrap : public Napi::ObjectWrap{ //class constructor static Napi::FunctionReference constructor; //wrapped methods + Napi::Value setText(const Napi::CallbackInfo& info); QWIDGET_WRAPPED_METHODS_DECLARATION }; diff --git a/src/lib/QtWidgets/QRadioButton/index.ts b/src/lib/QtWidgets/QRadioButton/index.ts index c0113b6a3..ffda80f45 100644 --- a/src/lib/QtWidgets/QRadioButton/index.ts +++ b/src/lib/QtWidgets/QRadioButton/index.ts @@ -19,5 +19,9 @@ export class QRadioButton extends NodeWidget { this.native = native; this.parent = parent; // bind member functions + this.setText.bind(this); + } + setText(text: string | number) { + this.native.setText(`${text}`); } }