The 30-year-old worked under current R's boss Mark Warburton at Brentford during the 2014-15 campaign, scoring 17 league goals as the Bees reached the Championship play-offs.
Gray told QPR's official website: "I am really excited. Obviously the manager had a massive part to play in it, having worked with him before.
"I wanted to go somewhere where I can try to get back to my best and I felt this was the best option. It was an easy decision.
"I love playing in the Championship, I love the Tuesday night games. I was in a position where I could have gone abroad and had a nice lifestyle and enjoyed the sun, but that's not what I wanted to do."
Warburton added: "I am absolutely delighted we have been able to bring Andre in.
"I know him very well, he is a very good character around the place and he will fit in very well to the group."