QPR have reached an agreement with Real Madrid to sign Spanish midfielder Esteban Granero on a permanent deal.