fix tab switching in Qt5

See the 1st commit, 911717d, for the fix. The other one adds type safety but does not fix any bug ;-)