The second point is more important: qsort has a worst case behaviour of O(N²), that''s enormeous. On the average data, this worst case scenario is almost never met, but z-sorted faces are no average data. Depending on how you manage your 3D structures, it is very likely, that they are already sorted in the more or less correct order (from the last frame). Now qsort will expose it''s worst case behaviour on exactly this type of data. Not good.
I like natural mergesort for this task. Worst case behaviour is O(N log2 N), which corresponds to the best case behaviour of qsort. But NAT-mergesort''s best case behaviour is only O(N), and that''s very fast. It is met, when most parts of your data are already sorted in the right order. Furthermore, NAT-mergesort is *not* recursive, stable and very simple to implement.
Just make sure, that you store the results of your sort from the previous frame to be able to take advantage of the algorithm.
There are good documents on the net about natural mergesort, it''s a well known algorithm, just use Google. But there is one page that proposes a slightly modified version of it, which runs about 60% faster, unfortunately the page is in german only. You could try to translate it somehow, or just rip the code

For your problem, you could do it as follows:
* Make an initial empty plane list
Then for each frame:
1) update your list with newly visible planes (and delete invisible ones), but do not destroy the old sort order of the list.
2) Sort the planes based on z distance (the algorithm will take advantage of the old sort order from the previous frame).
3) Render your list (but do *not* delete the entries !)
4) goto 1
hope it helped.
A.H aka Blueshift