PDA

View Full Version : Catching all Signals from widget in QTest



cszawisza
30th July 2014, 08:17
Hi!

I need to catch all signals emitted from a widget using QSignalSpy (or something else), is there a way to do that? It can by only number of those signals without any other info.

anda_skoa
30th July 2014, 10:14
You can list all signals of a type by iterating over the methods of its QMetaObject and checking for QMetaMethods for signals.

You could then create a list of signal spys, each connected to one signal, or connect all signals to a custom slot in a receiver object.

Cheers,
_

cszawisza
5th August 2014, 13:23
If somebody want to know how to do that I paste my code.


#include <QSignalSpy>

class QAllSignalSpy : public QList<QSignalSpy*>
{

public:
explicit QAllSignalSpy(QObject *parent){
QObject *object = parent;
const QMetaObject *me = object->metaObject();
int metaCount = me->methodCount();
for(int i = 0;i<metaCount;i++){
QMetaMethod mm = me->method(i);
if (mm.methodType() == QMetaMethod::Signal){
QString method = QString::number(2)+ mm.methodSignature().constData();
this->append( new QSignalSpy(object, method.toLatin1().constData() ) );
}
}
}

int signalCount(){
int all = 0;
for(int i=0;i<this->size(); i++)
all += this->at(i)->count();
return all;
}
};

enjoy! ;)

Ignitor
10th December 2017, 23:14
I have just published a tiny header-only library which does exactly this: QSignalInspector (https://github.com/j-ulrich/QSignalInspector)