Miscellaneous cppcheck and other fixes

Like #268 but for master, not stable-0.8. Sorry!

I'm happy to squash things if the commit history gets too detailed ;)
Our style is "QVariant& x". Logic behind that is that the ampersand changes the type, not the variable(-name).