Please note, if the QLn has continuous media loaded but is set to noncontinuous (gap or bar), then it will attempt to print, but will feed trying to find a gap or mark. After feeding, it will display an out of media error on the LCD screen, which is similar to the behavior you are trying to achieve. The issue for your use case is if the QLn has labels loaded but is set to continuous media, the printer will not detect an error and will just print over multiple labels.
It is not possible to query what media type the printer is set to using CPCL, but there is a SGD command (see page 722 of the ZPL Programming Guide):
! U1 getvar "ezpl.media_type"
You can set the media type using the same SGD command:
! U1 setvar "ezpl.media_type" "value"
where "value" can be "gap/notch", "mark", or "continuous".
For your use case, you might consider setting the printer to calibrate the media sensors whenever the media door is closed instead of setting the media type. Then you can programmatically check the media type before sending the print job to the printer and give an error in the program instead of relying on the printer to do so.
To set the printer to automatically calibrate the media when the media door is shut, use this SGD command (page 718 of the ZPL Programming Guide):
! U1 setvar "ezpl.head_close_action" "calibrate"