What is the purpose of Alt-F4?
Solution 1:
The shortcut Alt-F4 send a close message to the window, as when you press the little x button on the title bar. It is a windows manager configuration.
It depends upon the application whether to respond to this event closing all together the application, or iconize (i.e. like xchat can be configured) or other.
The Ctrl-Q shortcut you mention is not universal, every application can have its own. For example evince
use Ctrl-W, some other use Ctrl-Q to close, Ctrl-W to close a single tab and Shift-Ctrl-W to close all tabs (but not all windows).
Solution 2:
This entirely depends on the application.
By default, applications bind Alt+F4 such that it does the same as closing the window. For some applications that means quitting (like the Calculator), for others it might mean putting them in the background (like Empathy).
The job of Ctrl+Q is the developers' free choice, but convention dictates that it quits the application.
In short: Alt+F4 will normally do the same thing as clicking . If that only hides the windows, Ctrl+Q will normally quit the application.