The midfielder is moving to the ambitious London club.
The 25-year-old, deemed surplus to requirements by Jose Mourinho, is Mark Hughes' ninth summer signing as he aims to improve on the west London side's 17th-place finish last year.
Hughes told the club's official website: "He is a great player, first and foremost. You don’t play at a club like Real Madrid if you’re not.
"He has got great energy and is technically very gifted, as you would expect. He is an all-round excellent midfielder.
“He has been there from the age of nine, so this has been a huge decision for him. He is very well regarded there and for him to leave a club of that stature to come to us shows the belief he has in what we are trying to do."
Granero spent two years at Getafe before returning to Los Blancos where he played 60 games in the last three seasons.
The midfielder will wear the number 14 shirt and added: "I love the passion of the English fans and from what I know QPR supporters are amongst the very best.
"When I spoke to Mark [Hughes] and Mike, as well as Tony [Fernandes] I was convinced that I wanted to be part of this project, which has no limits.
"Players that have joined before me are as excited as I am about what QPR can become, one of the great teams in England."
Follow GOAL.COM USA on