You are very right to be asking that question and that is a variable we cannot really predict.
I do know however that there are certain properties on the Pearl that offer you a residence permit when you buy.
So even if you loos your job you will still be able to live in Doha.