will there be a problem in comming to Doha with x company's Visa and then later or obtaining NOC from x and working for Y. Is it legal doing that way? will there be any problems from the Labour ministry?

Kindly advise?