QSignalMapper Example Revisited

Qt Library

Qt Library

Several years ago I wrote a short piece on QSignalMapper to give a quick example of how it can be used. Since then, Qt5 has been released and C++11 is now A Thing.

One of the cool things introduced in Qt5 is a new overload for the QObject::connect() method:

This means we can use function pointers instead of the old (char *) based method. One of the big advantages of using the new method is that it can check signal/slot connections at compile-time instead of only at run-time. If the signature of either the sender or receiver changes the code will fail to compile. (If you are using C++11 and like to write “clever” code, you can now use lambda expressions as well!) There’s a decent overview of the new method in this blog post by Olivier Goffart.

I recently started updating my aging codebase to Qt5 and C++11 and one of the things I’m changing is all my connections to use the new format. I ran into an issue almost immediately that I thought I’d document in case I can save someone some time.

Continue reading