Qual corresponds to the English which, but in opposite to the English which, that is invariable, it has to agree in gender and number with the noun it refers to.
We have to distinguish between the use as an interrogative adjective and an interrogative pronoun.
interrogative adjective: Which car do you like?
interrogative pronoun: Which is the best?
Qual / quais competes with que when used as an interrogative adverb. If used as an interrogative pronoun, the difference is clear.
a) To ask for something unknown: What do you want?
b) To ask for an element of a group: Which do you want?
In case a) we ask for something unknown. The answer could be anything: a cup of coffee, to go to the beach, 200 dollars etc. etc.. In case two we refere to a group, and we ask for an element of this group. If there are several trousers the answer could be the blue one or something like that. In case b) the participants of the dialogue have in mind a group of elements and the answer to the question is an element of this group. If qual / quais is used as an interrogative pronoun the difference is very clear.
If qual / quais are used as interrogative adjectives we can distinguish three different situations.
1) only what is possible: What bread is that?
2) only which is possible: Which one did you choose?
3) Both are possible: Which / what car fits with your budget?
In 2) we ask obviously for properties. We have a determined bread in front of our eyes and we want a description of this bread (white bread, rye bread, leavened bread, bread with salt, bread with raisens, with milk, without milk etc.) We don't ask for an element of group, we ask for properties. In 2) we ask for an element of a group. In 3) both are possible. The cars can be considered as a group of elements, for instance the different companies, Chrysler, Ford, Toyota, etc.. Then the answer would be for instance a Suzuki or Fiat. However the possible answer could be as well the description of properties, small, not very thirsty, easy to maintain etc..
The table below show the difference between que / qual in a more systematic way.
The difference between que and qual / quais can be shown as well in a more systematic way.
I is aked for a property.
intersection (both are possible)
It is asked for an element of a group.
What is that?
There is no intersection.
qual / quais
Which one you mean?
It is asked for a property
It is asked for an element of a group.
What kind of bread it that?
que, qual / quais
Which flowers do you like?
What flowers do you like?
qual / quais
Which one was it?
Concerning the interrogative pronouns que and qual / quais the situation is clear. It is possible that both can be used, but the meaning would change completely.
1) Que querem?
What do you want?
2) Qual querem?
Which do you want?
Used as an adjective que / what asks for properties.
Used as an adjective que / what asks for properties. The one who makes this question expects more information about the object or about which element of a group one is talking about. Concerning the last point, description of characteristics, what and which competes if used as adjectives: What flowers do you like? <=> Which flowers do you like? See 22.3.
In the case that what is used as an adjective it depends as well from the context whether which is possible or not.
Que carro tem o senhor?
What (kind) of car do you have?
Carro, car, is singular. If someone only has one car it is obvious that he question is not about an element of a group. There is none. However it can be unclear what kind of car he has, a Peugeot, Volvo, Seat, Chrysler, Toyota, diesel vehicle, gasoline vehicle, plattform truck, sports car etc.. In this case only que and what are possible.
At the other end we have questions, where we know from the context that we ask for an element of a group.
Qual casa das celebridades citadas é a sua favorita?
Which of the houses of the celebrities mentioned above is your favorite?
In this case the group is explicetely mentioned and we ask for an element of this group. In a case like this even if used as an adjective which cannot be substituted by what. Beside these two extreme cases there are a lot of cases in between where what and which are possible.
Qual casa mais combina com você?
Que casa mais combina com você?
Which / What house fits you best?
Quais homens eram considerados cidadãos no período imperial brasileiro?
Que homens eram considerados cidadãos no período imperial brasileiro?
Which / What men where considered citizens at the time of the imperial Brasil?
In these sentences it is unclear whether it is asked for an element of a group or for properties, in other words, it is unclear whether an element is defined by a set of properties or referred directly.
Since the case where both are possible is very common, you can find in many grammar books the assertion that there is no difference between que and qual / quais. This is not true. First if used as pronouns there is a big difference between que and qual / quais and second even in the case that they are used as adjectives very often they are not interchangeable.