diff options
Diffstat (limited to 'tests/tst_qtdotnet/foo.cpp')
-rw-r--r-- | tests/tst_qtdotnet/foo.cpp | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/tests/tst_qtdotnet/foo.cpp b/tests/tst_qtdotnet/foo.cpp index 8c8c3d3..789ec1b 100644 --- a/tests/tst_qtdotnet/foo.cpp +++ b/tests/tst_qtdotnet/foo.cpp @@ -7,7 +7,7 @@ #include <qdotnetevent.h> -struct FooPrivate final : QDotNetObject::IEventHandler +struct FooPrivate final : QDotNetEventHandler { Foo *q; FooPrivate(Foo *q) : q(q) {} @@ -17,12 +17,16 @@ struct FooPrivate final : QDotNetObject::IEventHandler QDotNetFunction<QString> bar; QDotNetFunction<void, QString> setBar; + QDotNetType typePropertyEvent = nullptr; + void handleEvent(const QString &eventName, QDotNetObject &sender, QDotNetObject &args) override { if (eventName != "PropertyChanged") return; - if (args.type().fullName() != QDotNetPropertyEvent::FullyQualifiedTypeName) + if (!typePropertyEvent.isValid()) + typePropertyEvent = QDotNetType::typeOf<QDotNetPropertyEvent>(); + if (!args.type().equals(typePropertyEvent)) return; const auto propertyChangedEvent = args.cast<QDotNetPropertyEvent>(); @@ -37,13 +41,13 @@ Foo::Foo() : d(new FooPrivate(this)) { const auto ctor = constructor<Foo, Null<IBarTransformation>>(); *this = ctor(nullptr); - subscribeEvent("PropertyChanged", d); + subscribe("PropertyChanged", d); } Foo::Foo(const IBarTransformation &transformation) : d(new FooPrivate(this)) { *this = constructor(d->ctor).invoke(*this, transformation); - subscribeEvent("PropertyChanged", d); + subscribe("PropertyChanged", d); } Foo::~Foo() @@ -61,10 +65,28 @@ void Foo::setBar(const QString &value) method("set_Bar", d->setBar).invoke(*this, value); } -IBarTransformation::IBarTransformation() : QDotNetInterface(FullyQualifiedTypeName) +IBarTransformation::IBarTransformation() : QDotNetInterface(AssemblyQualifiedName, nullptr) { - setCallback<QString, QString>("Transform", { QDotNetParameter::String, UnmanagedType::LPWStr }, - [this](const QString &bar) { + setCallback<QString, QString>("Transform", + [this](void *, const QString &bar) { return transform(bar); }); + + setCallback<Uri, int>("GetUri", + [this](void *, int n) + { + return getUri(n); + }); + + setCallback<void, Uri>("SetUri", + [this](void *, Uri uri) + { + setUri(uri); + }); + + setCallback<int>("GetNumber", + [this](void *) + { + return getNumber(); + }); } |