You could use getqflist()
to retrieve the contents of the quickfix window, filter it, and the use setqflist()
to replace the contents, then it should behave properly.
There are some plugins that you could check:
QFixToggle : Toggle the visibility of the quickfix window - changing the visibility would be equivalent to deleting, and make it easier to correct if you delete too much.