The topic is discussed at length in this other thread. Short answer: how people and teams qualify varies by sport, but in general, it seems like the individual sport governing bodies now try to not have clearly unqualified athletes compete.
Generally speaking, AIUI, each event has some level of limit as to how many athletes/teams qualify, for logistics, if nothing else.