Back port code from master to stable/0.9

Everything but Qt 4 support removal.