QT signal/slot alternative

399 views
Skip to first unread message

Tomas Polovincak

unread,
Feb 2, 2013, 10:00:46 PM2/2/13
to mi...@dartlang.org
I am looking for some pattern, principe, mechanism, etc... how to replace something like QT/pyQT signal/slot in Dart/JavaScript. I try implement little concept of signals (github) with optional arguments length emit() method, object mapper for multiple signals to one slot. 

It use noSuchMethod so there are problems with arguments type control, sender object must be set for every signal and SignalMapper must be checked before emitting data, etc. If Dart have something like JavaScript arguments it will be very useful or mirrors will help fix some problems when come completly to dart and dart2js.

At this moment is there some way to fundamentally improve my signals test library, or how to replace it with something completely different?

Meow

unread,
Feb 2, 2013, 11:53:13 PM2/2/13
to mi...@dartlang.org

Tomas Polovincak

unread,
Feb 3, 2013, 12:21:04 AM2/3/13
to mi...@dartlang.org
Streams (or EventDispatchers) isnt good alternative. They works a little different. With stream you pass through only one kind of data (Event, Object, ....). With signal/slot connection you can send more data on one emit. For example you have signals defined like 

Signal mySignal1; #qt define signal types (String, num, bool)

signal mySignal2
; #qt define signal types (String, String);

then when you emit them it looks like this

mySignal1.emit("Hi iam Cool signal", 1, true);
mySlot1
(String text, num count, bool isCool) {} #slot callback get this 3 arguments

mySignal1
.emit("Old", "New");
mySlot2(String oldText, String newText); #slot get this 2 arguments

now when you can do this with Streams you must specific some wrapper arround data {"oldText": "Old", "newText": "New"} or some 
Object wrapper new SignalData({"oldText": "Old", "newText": "New"}) , now how you can get this data from wrapper? 

slot(objectWrapper) {
    objectWrapper
.data['oldText'];
}

or define object wraper with noSuchMethod and mapping data List to getters

slot(objectWrapper) {
    objectWrapper
.oldText;
}

or you can create every time you would like to use signal connection like a stream new SignalData object extendet from some BaseSignalData object to have arguments type control? Then you have to deal with same problems(some of them could be resolved with noSuchMethod and mirrors maybe) like my "stupid" implementation of this mechanism but i have easier way to transfer data from signal to slots if you understand me.
Reply all
Reply to author
Forward
0 new messages