No need to leave the country, once you get the visa then goto medical commission tell them that convert visit to residence, you will be charged 500QAR for that.

Note: If your wife is on arrival visa , should be exit and enter with new visa.