League One side Gillingham have signed QPR defender Max Ehmer on a free transfer.
The 23-year-old German had a loan spell with the Gills last season and went on to score one goal in 29 appearances for the Kent club.
"Max showed us the qualities he has as a player and what he is as an individual," Gills boss Justin Edinburgh told BBC Radio Kent.
"He is one we wanted to secure and it has been a bit more difficult than we thought. Credit to the chairman, who has worked tirelessly on this one."
Ehmer has agreed a three-year contract with Gillingham.