The 30-year-old joins as a free agent having been released by the Hammers this summer and links up with former Portsmouth boss Harry Redknapp.
O'Neil has trained with Rangers for the last fortnight and has now agreed to a permanent stay at Loftus Road.
"Gary's a good player and a good pro," Redknapp told the club's official website. "He was offered a new deal at West Ham but he decided he fancied coming here because he feels maybe he'll get more game time at QPR.
"He can run all day long, he's good on the ball, a good passer, he sees all the pictures in front of him and is a top professional.
"We've got plenty of options in that department now, but he'll certainly add to what we've got - he's a good, good player and will be a fine acquisition for us."
O'Neil added: "The challenge here is an exciting one. Obviously I know Harry well and he was a big factor in me coming here. The promotion season we had under him at Portsmouth was fantastic.
"He's played a massive role in my development as a player and now I'm back playing for him again and I want to repay him by helping this club get back into the Premier League.
"Having been in and around the squad for the last few weeks, I've seen how united the squad are to achieve what we all want to do.
"The togetherness is there - it's a really happy camp and there's a real good feel to the place."
Source: PA
Source: PA