Created
September 29, 2016 11:27
-
-
Save fferri/7e29115e8e786604ca8d7714093644f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QtCore> | |
class SignalSpy { | |
static QThreadStorage<bool> entered; | |
static void signalBegin(QObject *caller, int signalIndex, void **); | |
static void slotBegin(QObject *caller, int index, void **); | |
public: | |
static void start(); | |
}; | |
#include "signal_spy.h" | |
#include <5.5.0/QtCore/private/qobject_p.h> | |
static int signalToMethodIndex(const QMetaObject * mo, int signal) | |
{ | |
Q_ASSERT(signal >= 0); | |
for(int i = 0; i < mo->methodCount(); ++i) | |
{ | |
if(mo->method(i).methodType() == QMetaMethod::Signal) | |
{ | |
if(signal == 0) return i; | |
--signal; | |
} | |
} | |
return -1; | |
} | |
static bool spyCondition(QObject *caller) | |
{ | |
return caller->objectName() == "UIProxy" || caller->objectName() == "UIFunctions"; | |
} | |
QThreadStorage<bool> SignalSpy::entered; | |
void SignalSpy::signalBegin(QObject *caller, int signalIndex, void **) | |
{ | |
if(entered.localData()) return; | |
QScopedValueRollback<bool> roll(entered.localData(), true); | |
if(spyCondition(caller)) | |
{ | |
int index = signalToMethodIndex(caller->metaObject(), signalIndex); | |
if(index >= 0) | |
qDebug() << "SIGNAL" << caller << caller->metaObject()->method(index).methodSignature(); | |
} | |
} | |
void SignalSpy::slotBegin(QObject *caller, int index, void **) | |
{ | |
if(entered.localData()) return; | |
QScopedValueRollback<bool> roll(entered.localData(), true); | |
if(spyCondition(caller)) | |
{ | |
qDebug() << "SLOT" << caller << caller->metaObject()->method(index).methodSignature(); | |
} | |
} | |
void SignalSpy::start() | |
{ | |
QSignalSpyCallbackSet set = {&signalBegin, &slotBegin, 0L, 0L}; | |
qt_signal_spy_callback_set = set; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment