Both Qui and Que are relative pronouns. Their function grammatically is to reduce redundancy.
Que = Relative pronoun + subject + verb
Que is the direct object.
Quick refresher:
A direct object is a person or thing that receives the action of a verb. An indirect object is a person or thing in a sentence.
- Le train que j’ai prend = The train that I took
- Le livre que j’ai lu beaucoup fois = The book that I read many times
Qui = Relative pronoun + verb
The function of qui is to be the subject for the subordinating clause
- L’homme qui etait le plus grand = The man who was the tallest
- Le chat qui habite dans la cave = The chat that lives in the basement
Another function of qui is to replace indirect objects.
- La fille à qui j’ai parle est…
- L’homme à qui j’ai vu est…