I am a little confused with what you mean by legal.
If I am correct your questioning if the marriage will be legally recognized? The answer is yes, as long as both parties are free to marry and are of the legal age. By free to marry I mean not already married, the age requirements depend for the country they are getting married in.
I assume you mean can you get married in Canada while on a TRV? The answer to that again is yes.
The requirements for each province are different, since you are talking Quebec(I assume), you should talk to someone at the local city call. I may be wrong but I believe the only requirements are legal ID/passport, medicals and security checks are not a part of getting married(as far as I know).