Home

sigfwd

sigfwd is a library for connecting Qt signals to regular C++ functions and functors.

Why?

Some criticisms leveled against Qt's signals and slots mechanism include:

  • not type safe
  • adds another layer of complexity to an already complex language (C++)
  • requires extra boiler plate (signals, slots, Q_OBJECT, etc)
  • having to derive from QObject just to receive a signal increases coupling
  • inflexible; you can only connect signals to specially labeled methods of a QObject.
  • an extra and sometimes brittle build step ("moc") is required to wire-up the underlying "meta machinery"

sigfwd aims to address or ease these problems in one way or another.

Quick demo

void on_slide(int &old_value, int new_value) { old_value = new_value; }
void on_display(int value) { QMessageBox::information(0, "Report", QString::number(value)); }

// ...

using boost::bind; using boost::ref;
int value = 0; // slider is bound to this int and button displays its value when clicked

sigfwd::connect(slider, SIGNAL(valueChanged(int)), bind(&on_slide, ref(value), _1));
sigfwd::connect(button, SIGNAL(clicked()),         bind(&on_display, ref(value)));

demo

The code is designed to work with Visual C++ 2008, MinGW 4.4 and Apple's g++ 4.0.1 (and later compilers in these series). It is likely to work on other systems with recent g++ compilers too (e.g. Linux), but they remain untested thus far.

sigfwd was developed against Qt 4.6.3 and version 1.39.0 of the boost headers, though any Qt4 release and recent set of boost headers should suffice.

More

Todo

Due to the fact that I've so far failed to get a cross-platform build up and running without having to tweak the build scripts every time I change between MinGW, MSVC and Apple's GCC, there are no tests. So tread carefully.

Once I get a sensible build working, I will add some. Hopefully this will happen soon.

It might also be useful to have some kind of scoped_connection object at some point. Haven't found a need yet, though.

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.