I STRONGLY NEED to know slot where signal is connected to.
-
Just give me idea - did you inherit QObject, or did you patch it's source code, or made something else?
Why not ask Qt team to just "open the door"? I'm sure lots of people would like have this feature. In other forums I discussed it and many developers told they need same. If we all together will ask for it - probably this finally be solved.
-
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...
-
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.
-
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.
-
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.
-
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;
}@ -
You can make a merge request in qitorious and add it there.
But whether it goes in, I can't tell you. -
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. -
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?...
-
[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_connectionYou may also want to look at :
@void QObject::connectNotify ( const char * signal ) and void QObject::disconnectNotify ( const char * signal )@ -
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...
-
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.
-
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
-
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.
-
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.
-
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.
-
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.
-
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;
@ -
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 -
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...