The craziest thing to me about qualified immunity is that no law was ever passed to create it. It was invented out of whole cloth by 20 years of supreme court decisions.
The big problem with QI in the US is the phrase "clearly established" which has been interpreted extremely strictly to mean there needs to be a case already ruled on with essentially exactly the same circumstances sometimes tiny differences mean a cop gets away with clearly egregious conduct.
On top of that they get a chance to have the case thrown out immediately for QI reasons and if that's denied they can immediately appeal that ruling. Also the Supreme Court essentially only takes cases that grant immunity rather than stripping it meaning it's constantly getting tougher and tougher.
Many, less controversial doctrines and holdings come to pass the same way, from the 'laws' against insider trading, to the current incorporation of the bill of rights.[1][2]