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. I STRONGLY NEED to know slot where signal is connected to.
Qt 6.11 is out! See what's new in the release blog

I STRONGLY NEED to know slot where signal is connected to.

Scheduled Pinned Locked Moved General and Desktop
32 Posts 9 Posters 47.5k Views 1 Watching
  • 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.
  • A Offline
    A Offline
    andre
    wrote on last edited by
    #8

    Something else: I did (sort of) what I described about an hour ago (under the 'Edit:' note): do my own bookkeeping.

    If you "just ask", it may or may be accepted as a task, but if it is, probably a low priority one. Note that Qt managed to have signals and slots be very useful for many, many years without this functionality. I don't think many developers would need it. You could see if there is already a ticket for it in "Jira":http://bugreports.qt.nokia.com, and if there is, vote for it. If it is true that so many developers need this, then it should already been reported, right? However, don't get your hopes up to get this in Qt if you're not willing to contribute the code for it yourself. Open governance works both ways...

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #9

      Note that adding these options to the interface would mean weakening the very thing the whole signal/slot system was designed to more or less enforce. This means that you would have to come up with some very strong use cases indeed, if you want this in the public API.

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #10

        Signal/slot is the basic mechanism of Qt. It appeared in Qt from first time, it works well for years and it doesn't look like a subject to be removed or significantly changed. It can be differently implemented under cover of Qt but I don't see reason why any object itself or why any side object cannot know where signal is connected. At middle 90-s I was registered developer of BeOS. This system had very similar mechanism but OS-wide. And there were no difficulties to know receiver to which sender is connected. (BeOS is dead but because of completely different reason - it was too good for Kingdom Of M$)

        Now I see class QObjectPrivate which holds all functionality needed to work with classes and signals in more advanced way. But it is not documented what means it can be changed. All is needed from Nokia - open this class for public, document it and promise not to change without notifications.

        And of course needed one method in QObject:

        @QObjectPrivate* QObject::getPrivates()
        {
        return d_ptr;
        }@

        or method returning object of class QObjectConnectionListVector which holds all connection info.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #11

          Not a chance of that going to happen. That class is private for a reason. Just exposing it like you propose shows me that you have no idea about API design, binary compatibiliy constraints and all that have to do with that. If the functionality to query for connected objects would be added (and that is a very big if), it would take the form of a method on QObject or some other public class. No way QobjectPrivate will become part of the public API.

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #12

            Exactly the content of QObjectConnectionListVector for current QObject is enough for professionals. It could be returned by the one call of new QObject method. Just only one method...

            @QObjectConnectionListVector QObject::getConnectionsList()
            {
            return *d_ptr->ConnectionsList;
            }@

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #13

              You can make a merge request in qitorious and add it there.
              But whether it goes in, I can't tell you.

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • ? Offline
                ? Offline
                A Former User
                wrote on last edited by
                #14

                Track it yourself. Write a wrapper of QObject::connect which register the connections somewhere, and after you manage it. something like:

                @void register_connect( const QObject * sender, const char * signal,
                const QObject * receiver, const char * method,
                Qt::ConnectionType type = Qt::AutoConnection )
                {
                if(QObject::connect(sender, signal, receiver, method, type)){
                save_connection(sender, signal, receiver, method, type);
                }

                }

                class Connections{
                typedef struct{
                const QObject * object;
                const char * method;
                }Endpoint;

                Endpoint sender;
                QList<Endpoint> receivers;
                

                };
                @
                save_connection(..) can use a static structure of objects(beware of race conditions) to record the connection.
                And then your function
                @
                QList<const char*> slotsConnected( const char* signal );
                @
                which would be more like
                @
                QList<const char*> slotsConnected( const QObject * sender,const char* signal );
                @
                can retrieve all connections using this particular structure of Connections objects.

                1 Reply Last reply
                0
                • ? Offline
                  ? Offline
                  A Former User
                  wrote on last edited by
                  #15

                  Well I know this solution. But this does allow register new connections only. This solves problem partially. And exactly this duplicates information already stored inside QObject.

                  What if registered connection will be disconnected using simple disconnect() function?...

                  1 Reply Last reply
                  0
                  • ? Offline
                    ? Offline
                    A Former User
                    wrote on last edited by
                    #16

                    [quote author="Gourmand" date="1308159679"]But this does allow register new connections only.
                    [/quote]
                    If you have control over your entire library then you can change for your own connections. Describe a bit more the issue,please.

                    [quote author="Gourmand" date="1308159679"]
                    What if registered connection will be disconnected using simple disconnect() function?...
                    [/quote]
                    someObject->disconnect() has a static equivalent, so you'll need to change every occurrence by an equivalence to save_connection

                    You may also want to look at :
                    @void QObject::connectNotify ( const char * signal ) and void QObject::disconnectNotify ( const char * signal )@

                    1 Reply Last reply
                    0
                    • ? Offline
                      ? Offline
                      A Former User
                      wrote on last edited by
                      #17

                      Exactly registering is not as simple as you think. To make this good working and safe - some complex code required. First, connection deleting can be done by different ways, Second this all must be thread safe. Actually this requires more attention than you show here. But the motto of Qt is "Code less - create more". To code less I need to know where each signal is connected...

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #18

                        I think you have been given enough pointers on how you might solve this. It seems to me, you are not willing to take any of them. In the end, you probably will end up having to patch Qt, and either distribute your own, patched version, or argue a convincing case to get your patch merged in Qt proper.

                        1 Reply Last reply
                        1
                        • ? Offline
                          ? Offline
                          A Former User
                          wrote on last edited by
                          #19

                          I already implemented

                          @class ConnectorRegister
                          {
                          public:
                          ConnectorRegister();
                          ~ConnectorRegister();

                          bool do_connect(  QObject * sender,  char * signal,
                                           QObject * receiver,  char * slot,
                                          Qt::ConnectionType type = Qt::AutoConnection );
                          bool do_disconnect(  QObject * sender,  char * signal,
                                               QObject * receiver,  char * slot );
                          bool are_connected(  QObject *sender,  char *signal,
                                                QObject *receiver,  char *slot );
                          Connection where_connected( QObject* object,  char * socket, bool sender );
                          Qt::ConnectionType get_type(  QObject *sender,  char *signal,
                                                        QObject *receiver,  char *slot );
                          

                          private:
                          QList<Connection> connections;
                          };@

                          with some extra functionality. For example it stores connections in it's destructor to file and restores them in constructor. And it is thread safe. This class is much better and more powerful than all discussed here. That means - I know what I'm talking about. The BEST solution will be if Qt will have ability get connection info legally from QtCore

                          1 Reply Last reply
                          0
                          • M Offline
                            M Offline
                            mlong
                            wrote on last edited by
                            #20

                            Taking a different approach to this problem (probably too little, too late), if it is a user action that connects or disconnects the signals and slots, wouldn't it just be simpler to keep track of the connection or disconnection requests that the user has made, rather than rely on introspection of the connections themselves? Saving the requests would be trivial, and then to reconnect them later on, you just read in the requests and make them in the order they were saved.

                            Software Engineer
                            My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                            1 Reply Last reply
                            0
                            • ? Offline
                              ? Offline
                              A Former User
                              wrote on last edited by
                              #21

                              I decided to make exactly that you are talking about. But this looks good only from beginning. This must be implemented very carefully but cannot solve all problems. If I would able get existing connections from Qt - then I'd not have these problems and code would be much more simple.

                              1 Reply Last reply
                              0
                              • G Offline
                                G Offline
                                giesbert
                                wrote on last edited by
                                #22

                                You can access the private stuff, but then you are not binary compatible. I know, there was already a discussion about that here on devnet.

                                If you include QObject_p.h you can cast and have access, but that's not officially.

                                And I don't think, the Trolls will add that to the API. Not only because one user likes to use it. And I personally don't know where this should be needed.

                                Nokia Certified Qt Specialist.
                                Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                1 Reply Last reply
                                1
                                • ? Offline
                                  ? Offline
                                  A Former User
                                  wrote on last edited by
                                  #23

                                  bq. If you include QObject_p.h you can cast and have access, but that’s not officially

                                  No, I can't. QObjectPrivate* QObject::d_ptr is private.

                                  And this would not be very useful. I analyzed Qt source code related to object connections. Internal data structures are adjusted to internal routines. They cannot be easy used in my code. Exactly new method and data structure needed to access connection info. That is why I turned to registering.

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    giesbert
                                    wrote on last edited by
                                    #24

                                    Believe me, it is possible to use the private data :-) It needs some tricks, but is possible...

                                    e.g. you can use:

                                    from QObject_p.h:

                                    @
                                    void Q_CORE_EXPORT qt_register_signal_spy_callbacks(const QSignalSpyCallbackSet &callback_set);
                                    extern QSignalSpyCallbackSet Q_CORE_EXPORT qt_signal_spy_callback_set;
                                    @

                                    Nokia Certified Qt Specialist.
                                    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      giesbert
                                      wrote on last edited by
                                      #25

                                      Now I recognize the topics I meant before:

                                      "how can I observe a custom qobject’s slot":http://developer.qt.nokia.com/forums/viewthread/4916
                                      "QSignalSpy Class Reference in the docs":http://developer.qt.nokia.com/doc/qt-4.7/qsignalspy.html

                                      Nokia Certified Qt Specialist.
                                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                      1 Reply Last reply
                                      0
                                      • ? Offline
                                        ? Offline
                                        A Former User
                                        wrote on last edited by
                                        #26

                                        I do not need "signal espionage". I need info about signals connections before any data will be send on them. Actually now I don't need even this. Untill I'll get any trouble with my current solution

                                        bq. Believe me, it is possible to use the private data

                                        If you mean creation of "twin" class with same data public then <reinterpret_cast> - it's a hack

                                        I do not like such hacks...

                                        1 Reply Last reply
                                        0
                                        • M Offline
                                          M Offline
                                          mlong
                                          wrote on last edited by
                                          #27

                                          Well, if you have a solution that works, I think that you're set. No functionality of the toolkit can be perfect for everyone, and there are always going to be restrictions (sometimes major, sometime minor) that you're going to have to work around. That's pretty much the nature of the beast.

                                          Should you have trouble with your current solution, even though it's not the one you dream and hope for, I'm sure that you can get some good productive feedback regarding ways to cope with it. I don't think any of us here would turn a deaf ear toward you if you present your problems objectively and are willing to listen to reasonable responses.

                                          But, the reality of things is that the solution you've been asking for (or, more properly, demanding) goes against one of the basic philosophies of Signals and Slots: the decoupling of caller and callee. And because of that, there's probably not going to be a lot that will happen from either the Trolls, or the community at large to change anything. With that said, there have been suggestions made as to how you can make the request formally, or propose code to be changed. Those mechanisms work when there is enough of a consensus or enough momentum from the community at large. Honestly, though, this isn't the forum for making those kinds of demands.

                                          "Code less, create more" is a great philosophy and a driving factor for our tools. But, that doesn't release us, as developers, from our duty of writing sound, constructive code and from sometimes having to be extra innovative and creative. The basic building blocks are there, and it's up to us to utilize them in the most proper way to accomplish our specific tasks.

                                          I hope that your solution you've ended up using turns out to be robust enough for you. Since you're in control of your code, you at least have the benefit of having some say in the degree of care that is given in maintaining the logic involved. Just stay on top of things, and document your code well.

                                          We've all had situations where we've had to use solutions what weren't our first choice, but that's just part of the adventure that is software development. Good luck!

                                          Software Engineer
                                          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                                          1 Reply Last reply
                                          1

                                          • Login

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