بسم الله الرحمن الرحيم
السلام عليكم ورحمة الله وبركاته
Callback vs SignalSlot
Inter-object Communication Mechanisms
الموضوع بكل بساطة هو مقارنة شاملة و تفصيلية(لو ممكن) حول آلية Signals And Slots في تقنية Qt و آلية Callback الموجودة في بعض التقنيات الرسومية العتيقة مثل Win32-API.
,.,.,.,.,.,.,.,.
ماذا يوجد في المصادر|الكُتب المتعلقة بتقنية Qt حوْل آلية SignalSlot و بعض المقارنات مع آلية callback المدعومة في بعض الورش و الإطارات الرسومية العتيقة مثل win32-API. بالطبع انا (كيوتيّة) مثقفة كيوتيّاً ولم يسبق لي دراسة Win32-API على الإطلاق ولا حتى اكاديمياً.
طبعاً كل المصادر تؤكد بأن آلية SignalSlots آمنة بيانياً Type-safe ولكن(يارب استر ما يزعلوا :happy: ) آلية callback ليست كذلك. الإقتباس التالي من مصدر Qt Assistant
Older toolkits achieve this kind of communication using callbacks. A callback is a pointer to a function, so if you want a processing function to notify you about some event you pass a pointer to another function (the callback) to the processing function. The processing function then calls the callback when appropriate. Callbacks have two fundamental flaws: Firstly, they are not type-safe. We can never be certain that the processing function will call the callback with the correct arguments. Secondly, the callback is strongly coupled to the processing function since the processing function must know which callback to call.
In Qt, we have an alternative to the callback technique: We use signals and slots.
.,.,,.,.,.,,.,.
الإقتباس التالي حوْل SignalSlot من كتاب Foundations of Qt Development
SIGNALS AND SLOTS UNDER THE HOOD
Signals and slots are implemented by Qt using function pointers. When calling emit with the signal as argument, you actually call the signal. The signal is a function implemented in the source file generated by the moc. This function calls any slots connected to the signal using the meta-objects of the objects holding the connected slots. The meta-objects contain function pointers to the slots, along with their names and argument types. They also contain a list of the available signals and their names and argument types. When calling connect,
you ask the meta-object to add the slot to the signal's calling list. If the arguments match, the connection is
made.
When matching arguments, the match is checked only for the arguments accepted by the slot. This
means that a slot that does not take any arguments matches all signals. The arguments not accepted by the
slot are simply dropped by the signal-emitting code.
عموماً انا عاملة الموضوع للنقاش الحُر حوْل الآليتين + حملة دعائية حول ثقافة Qt و قوة آليّاتها مقارنةً بآلية عتيقة ذائعة الصيت.
.,,.,..,,.,.
رمضان كريم
دمتم
:happy:
