Both sides started the game very brightly with wingers Victor Moses and Shaun Wright-Phillips threatening for each side.
In the seventh minute, Moses burst past Luke Young down the left-hand side and put a teasing cross in, but Hugo Rodallega just couldn't get on the end of it.
QPR began to dominate the game and looked to be the most likely to score. Joey Barton put in a good ball to DJ Campbell and the striker's header was saved in the 15th minute. Akos Buzsaky produced the moment of the match in the 29th minute, rolling past James McArthur before curling a 25 yard shot just past the post.
The hosts then took the lead thanks to a penalty conceded by a McCarthy, who handballed in the area. Heidar Helguson slotted home the penalty for his ninth of the season.
Buoyed by the goal, Mark Hughes's side kept coming forward and soon made it two through a Buzsaky free kick from 25 yards out that gave Al-Habsi no chance.
Wigan came out looking a completely different side in the second half with Martinez altering his formation, going with a straight 4-4-2. The changes worked as Rodallega put them right back into the game with a sensational free kick in the 66th minute.
QPR got the chance to the kill the game off as Caldwell brought down Helguson to give the home side a penalty. However, Al-Habsi kept the penalty out, which Helguson himself took.
Wigan pushed on looking for the equaliser but Tommy Smith ended hopes of a comeback with a goal in the 81st minute after some great work by Wright-Phillips.
That goal killed the game and QPR saw it out to secure Hughes's first win since replacing Neil Warnock at Loftus Road.