Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::anonymous_namespace{signaltools.cpp}::SignalWatcher Class Reference

Turns each emission of one signal of one object into an event. More...

Inheritance diagram for Sonde::anonymous_namespace{signaltools.cpp}::SignalWatcher:

Public Member Functions

 SignalWatcher (int watch, QObject *sender, const QMetaMethod &signal, EventSource *events)
 Connects signal of sender; emissions go to events as watch watch.
bool isConnected () const
 Whether the connection was made.
QString signature () const
 The watched signal's signature, e.g. "clicked(bool)".
QString what () const
 What is watched, e.g. "@0x.. QPushButton#ok clicked(bool)".
int qt_metacall (QMetaObject::Call call, int id, void **argv) override
 Handles the slot this watcher was connected to; everything else goes to QObject.

Private Member Functions

void record (void **argv)
 Emits one event for an emission whose arguments are argv[1..n].
void emitRecorded (const QVariantList &args)
 Emits the event for one emission whose arguments record() captured.

Private Attributes

int m_watch
 Watch id.
QMetaMethod m_signal
 The watched signal.
EventSource * m_events
 Where emissions go (this object's parent).
QString m_sender
 describeBrief() of the sender, taken when the watch started.
QString m_senderId
 idFor() of the sender.
bool m_connected = false
 Whether QMetaObject::connect succeeded.

Detailed Description

Turns each emission of one signal of one object into an event.

This is the technique QSignalSpy uses (QtTest can't be a dependency of Core): the class has no Q_OBJECT, connects the signal to the first method index after QObject's own, and handles calls to that index in qt_metacall(), where argv holds pointers to the signal's arguments. The connection is direct, so the arguments are read while they are valid. Only objects in the server's thread are watched (see signal_watch), but a worker thread can still emit such an object's signal: then the arguments are copied there and the event is made on this object's thread.


The documentation for this class was generated from the following file: