Use Trace2UML to trace Qt signals and slots

in Qt you use signals and slots to connect your classes and achieve a loose coupling between your classes. In addition to that, signal/slot connections can be asynchronous. So it would be ideal, to visualize signal and slot connections in a sequence diagram as an asynchronous event.

You can use Trace2UML to draw those events, If you have an object 0x123:class1 that sends an event to 0x3456:class2 the syntax in Tace2UML would be:

;at the time the signal is emit
0x123:class1 >-- 0x3456:class2 

;at the time the slot is called
0x123:class1 --> 0x3456:class2 

Unfortunately you can not code this in an easy way with Qt, because normally it is unknown to the signalling class, who is connected to it. the “connect” is done at a separate position.

In Trace2UML is a syntax to overcome this problem. Instead of knowing the destination of your signal inside your class, you can inform Trace2UML about your connections, at the position, the connection is done. Trace2UML maintains a connection list, and therefore can offer a simplified syntax for signals and slots:

;at the time you connect your signal
% 0x123 class1 mysignal 0x3456 class2 myslot 

;at the time the signal is emit
$ 0x123 mysignal

;at the time the slot is called
& 0x3456 myslot

Trace2UML understands this syntax and translates it into to correct commands. After read into Trace2UML the above lines are translated to:

;at the time you connect your signal
;Connect OK: 0x123 class1 mysignal 0x3456 class2 myslot
;at the time the signal is emit
! 0x123:class1
! 0x3456:class2
0007   0x123:class1 >-- 0x3456:class2 
;at the time the slot is called
0009   0x123:class1 --> 0x3456:class2 
howto/trace2umlinqt.txt · Last modified: 2015/05/13 16:36 by thomas
GNU Free Documentation License 1.3
Powered by PHP Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0 Valid HTML5