We need to go back to basic principles here
As a gentleman, clearly you would not go out of the house without a hat. As a gentleman, when you met a lady you would raise your hat as a matter of ettiquette. As a gentleman in uniform, you would not raise your hat so you would salute, the equivalent military greeting. Rank of wife or husband is not involved, only the status of the lady as a lady...