Git Product home page Git Product logo

qsignalinspector's Introduction

QSignalInspector

Build Status

Implements spying on all signals of a QObject instance.

QSignalInspector is very similar to QSignalSpy but it records the emission of all signals of a class. Internally, QSignalInspector uses one QSignalSpy for each of the signals.

Example

#include "MyObject.h"
#include "QSignalInspector.hpp"
#include <QTextStream>
#include <QCoreApplication>
#include <cstdio>

int main(int argc, char **argv)
{
	QCoreApplication app(argc, argv);

	// Setup object to be inspected
	MyQObject object;
	QSignalInspector inspector(&object);

	QObject::connect(&object, SIGNAL(finished()), &app, SLOT(quit()));
	object.start();
	app.exec();

	// Print the recorded signals
	QTextStream out(stdout);
	QSignalInspector::ConstIterator iter;
	for (iter = inspector.begin(); iter != inspector.end(); ++iter)
	{
		QSignalEmissionEvent emission = *iter;
		QStringList parameters;
		QList<QVariant>::ConstIterator paramIter;

		for (paramIter = emission.parameters.begin(); paramIter != emission.parameters.end(); ++paramIter)
			parameters << paramIter->toString();

		out << emission.signal.name() << "(" << parameters.join(", ") << ")" << endl;
	}

	return 0;
}

Usage

QSignalInspector(const QObject* object, bool includeParentClassSignals = true)

Creates a QSignalInspector recording the signal emissions of object.

Parameters
object - The object whose signals should be recorded.
includeParentClassSignals - If true, the signals of all parent classes of object are recorded as well. If false, only those signals are recorded that are declared by the last class in the inheritance hierarchy of object.

Then use the QSignalInspector as a QList<QSignalEmissionEvent> to retrieve the information about the emissions:

QSignalInspector mySignalInspector(&objectToBeWatched);

// Trigger emissions of signals ...

QSignalInspector::ConstIterator iter;
for (iter = mySignalInspector.constBegin(); iter != mySignalInspector.constEnd(); ++iter)
{
	const QSignalEmissionEvent event = *iter;
	// Do something with event ...
}

Where QSignalEmissionEvent is a simple struct:

/*! Struct representing one emission of a signal.
 */
struct QSignalEmissionEvent
{
	QMetaMethod signal;         //!< The QMetaMethod of the signal that was emitted.
	QDateTime timestamp;        //!< The time when the signal was emitted.
	QList<QVariant> parameters; //!< The parameter values of the emission.
};

Requirements

  • Qt 4.8 or later

License

Copyright (c) 2018 Jochen Ulrich

Licensed under MIT license.

qsignalinspector's People

Contributors

j-ulrich avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.