Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Auto-generate a map of all signal-slot connections

Auto-generate a map of all signal-slot connections

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cdwijs
    wrote on 21 Dec 2021, 16:01 last edited by
    #1

    Hi All,

    I have made a Qt program that uses signals and slots to exchange messages between the different modules.

    Now I have manually made a diagram that shows the relation between the different modules like this:

    501c31a5-cd14-45d7-85e2-d0c7da5886a2-image.png

    This is the code of the diagram, it can be rendered with graphwiz:

    digraph structure {
    node [shape=record]
    rankdir=LR
    ObjectA [label = "ObjectA | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
    ObjectB [label = "ObjectB | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
    ObjectC [label = "ObjectC | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
    ObjectA:sigA -> ObjectB:slotC
    ObjectB:sigA -> ObjectC:slotC
    ObjectC:sigA -> ObjectA:slotA }
    

    As far as I can tell, it should be possible to extract the above diagram from the source of the Qt program, the signals and slots can be extracted from the class declarations, and the lines in between them can be gathered from the connect () statements in the program.

    Does anybody know a tool that can scan the sourcecode of a Qt program, and then generate such a diagram?

    C 1 Reply Last reply 22 Dec 2021, 00:47
    0
    • M Offline
      M Offline
      mchinand
      wrote on 21 Dec 2021, 17:03 last edited by
      #2

      It doesn't create a graph like your example, but Gammaray will probably give you the most info about signal/slot connections. It displays info from a running Qt-based application, since signal/slot connections are often dynamically created and disconnected during the lifetime of a running application.

      1 Reply Last reply
      3
      • C cdwijs
        21 Dec 2021, 16:01

        Hi All,

        I have made a Qt program that uses signals and slots to exchange messages between the different modules.

        Now I have manually made a diagram that shows the relation between the different modules like this:

        501c31a5-cd14-45d7-85e2-d0c7da5886a2-image.png

        This is the code of the diagram, it can be rendered with graphwiz:

        digraph structure {
        node [shape=record]
        rankdir=LR
        ObjectA [label = "ObjectA | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
        ObjectB [label = "ObjectB | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
        ObjectC [label = "ObjectC | <slotA> slotA | <slotB> slotB | <slotC> slotC | <sigA>sigA" ]
        ObjectA:sigA -> ObjectB:slotC
        ObjectB:sigA -> ObjectC:slotC
        ObjectC:sigA -> ObjectA:slotA }
        

        As far as I can tell, it should be possible to extract the above diagram from the source of the Qt program, the signals and slots can be extracted from the class declarations, and the lines in between them can be gathered from the connect () statements in the program.

        Does anybody know a tool that can scan the sourcecode of a Qt program, and then generate such a diagram?

        C Offline
        C Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on 22 Dec 2021, 00:47 last edited by Chris Kawa
        #3

        @cdwijs said in Auto-generate a map of all signal-slot connections:

        As far as I can tell, it should be possible to extract the above diagram from the source of the Qt program

        Not really, no.

        the signals and slots can be extracted from the class declarations

        That's true, although keep in mind that C++ is pretty complex language. You can obscure stuff behind macros and templates. You'd have to pretty much use a compiler to get an accurate listing or at least mimic what Qt's moc tool does. There's also stuff like QUiLoader which create objects dynamically at runtime from text files. You can't track that just from source.

        You could use a QMetaObject to inspect a class, but that's a runtime inspection, not a static code analysis.

        (...) and the lines in between them can be gathered from the connect () statements in the program.

        Connections are made at runtime. You can't extract them from source code. They can be disconnected and reconnected multiple times in response to events that may or may not happen and objects are created and destroyed during runtime too.
        Also, imagine a function like this:

        void doConnection(QObject* src, const char* src_signal, QObject* dst, const char* dst_slot)
        {
           QObject::connect(src, src_signal, dst, dst_slot);
        }
        

        and function parameters are runtime user input. Analyzing this source tells you nothing about the objects or signals/slots.

        The best you could do is get a runtime snapshot of app state at a specific point in time and objects and connections existing at that time. That's what tools like GammaRay mentioned by @mchinand do.

        1 Reply Last reply
        3

        2/3

        21 Dec 2021, 17:03

        • Login

        • Login or register to search.
        2 out of 3
        • First post
          2/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved