Oxford English Dictionary
The OED says it comes from the first and last letters of quiet, and is chiefly used as on the (strict) q.t..
Their first quotation is:
1885 G. Moore Mummer's Wife ix. 126 It will be possible to have one spree on the strict q.t.
Victorian music
I found an antedating.
The University of Reading's Spellman Collection of Victorian Music Covers lists a song called You should see us on the strict "Q.T." from 1877 illustrated by Alfred Bryan, composed by Walter Redmond and written by Geoffrey Thorn.
The description is:
Caricature portrait, full length, of G H Macdermott; the titles of some of his songs around his feet.
And it includes the text:
(Chorus) Oh my! what a pious world this is
And how very good we all seem to be
What a duffing lot you find
If you only raise the blind
And see us on the strict "Q T."
The Facts on File Encyclopedia of Word and Phrase Origins
The Phrase Finder says:
As to on the q.t., in The Facts on File Encyclopedia of Word and Phrase Origins, Robert Hendrickson states:
"A British broadside ballad (1870) contained the line 'Whatever I tell you is on the Q.T.'"
It would be good to know the name of the ballad in order to follow up this assertion. Unfortunately, the author doesn't give it, from which we can only suppose he didn't know it himself. Without some supporting evidence that claim has to be in doubt.